Skip to content

Commit 449ccf9

Browse files
authored
Update docs to include Promise{T} and proper conditional syntax (#112)
1 parent f45d557 commit 449ccf9

3 files changed

Lines changed: 223 additions & 50 deletions

File tree

docs/built_ins.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ The Meta types are types that are generally not used directly, but represent fea
3636
The Host types are types that are involved in bridging Alan to the host language, allowing you to call native functions, declare native types, and require native 3rd party libraries.
3737

3838
* `Shared{T}` is a shared, reference-counted, thread-safe wrapper around a type. It allows the same data to be included in multiple other values without duplication. Auto-derefs on property/method access.
39+
* `Promise{T}` is a Javascript-only type used to annotate the return type of an `async` host function (which returns a `Promise` resolving to `T`). The compiler uses it to track function "color": any Alan function that calls something returning a `Promise{T}` is automatically inferred to be `async`, and the necessary `await`s are emitted in the generated Javascript. It is *transparent* in pure Alan code — a function body that awaits has an actual return type of `Promise{T}`, but a declared (or inferred) plain `T` still matches, so you never write `async` or `await` yourself. It has no meaning on the Rust backend.
3940
* `Binds{T, ...}` is the first built-in type that you *do* use directly. It's a generic type whose first argument is the string name of the type in the host language (Rust or Javascript) that you are compiling to. Extra arguments to the generic type are the types to provide to the generic arguments of the type assuming it is a generic type.
4041
* `Call{N, F}` takes a "callable" type as the first argument and a `Function{I, O}` declaration on how to "call" it as the second type. A `String` refers to a standard function, while rest of the "callable" types are defined below.
4142
* `Infix{O}` is the first "callable" type. It takes a `String` representation of an infix operator in the host language, which the compiler will turn into `(A op B)`, with `A` and `B` being the two arguments (it will be a compile-time error if the `Function{I, O}` does not specify exactly two arguments) and `op` is the operator symbol. Parentheses are always used to avoid needing to clarify operator precedence rules in the host language.

0 commit comments

Comments
 (0)