Syntax Reference
Comments
Section titled “Comments”// Line comment/* Block comment *//* Nested /* block */ comments */Declarations
Section titled “Declarations”const x = 42const name: string = "hello"export const PI = 3.14159
// Destructuringconst [a, b] = pairconst { name, age } = userFunction
Section titled “Function”fn name(param: Type) -> ReturnType { body}
export fn name(param: Type) -> ReturnType { body}
async fn name() -> Promise<T> { await expr}// Recordtype User { name: string, email: string,}
// Uniontype Shape { | Circle { radius: number } | Rectangle { width: number, height: number }}
// Newtype (single-value wrapper)type OrderId { number }
// String literal union (for npm interop)type HttpMethod = "GET" | "POST" | "PUT" | "DELETE"
// Aliastype Name = string
// Brandtype UserId = Brand<string, "UserId">
// Opaqueopaque type Email = string
// Deriving traitstype Point { x: number, y: number,} deriving (Display)For Block
Section titled “For Block”// Block form: group multiple functionsfor Type { fn method(self) -> ReturnType { body }}
// Inline form: single function, no blockexport for Type fn method(self) -> ReturnType { body}
for Array<User> { fn adults(self) -> Array<User> { self |> Array.filter(.age >= 18) }}Expressions
Section titled “Expressions”Literals
Section titled “Literals”42 // number3.14 // number1_000_000 // number with separators (underscores for readability)3.141_592 // float with separators0xFF_FF // hex with separators"hello" // string`hello ${name}` // template literaltrue // booleanfalse // boolean[1, 2, 3] // arrayUnderscores in number literals are purely visual — they are stripped during compilation. They can appear between any two digits but not at the start, end, or adjacent to a decimal point.
Operators
Section titled “Operators”a + b a - b a * b a / b a % b // arithmetica == b a != b a < b a > b // comparisona <= b a >= b // comparisona && b a || b !a // logicala |> f // pipeexpr? // unwrapvalue |> transformvalue |> f(other_arg, _) // placeholdera |> b |> c // chainingvalue |> match { ... } // pipe into matchmatch expr { pattern -> body, pattern when guard -> body, _ -> default,}
// Pipe into matchexpr |> match { pattern -> body, _ -> default,}Patterns: literals (42, "hello", true), ranges (1..10), variants (Ok(x)), records ({ x, y }), string patterns ("/users/{id}"), bindings (x), wildcard (_).
Function Call
Section titled “Function Call”f(a, b)f(name: value) // named argumentConstructor(a: 1) // record constructorConstructor(..existing, a: 2) // spread + updateCollect Block
Section titled “Collect Block”collect { const name = validateName(input.name)? const email = validateEmail(input.email)? ValidForm(name, email)}// Returns Result<T, Array<E>> — accumulates all errors from ?Constructors
Section titled “Constructors”Ok(value) // Result successErr(error) // Result failureSome(value) // Option presentNone // Option absentBuiltins
Section titled “Builtins”todo // placeholder, type never, emits warningunreachable // assert unreachable, type neverparse<T>(value) // runtime type validation, returns Result<T, Error>json |> parse<User>? // pipe form (most common)data |> parse<Array<Product>>? // validates arraysQualified Variants
Section titled “Qualified Variants”Filter.All // zero-arg variantFilter.Active // zero-arg variantOption.Some(value) // variant with dataResult.Ok(value) // variant with dataAnonymous Functions (Closures)
Section titled “Anonymous Functions (Closures)”fn(a, b) a + bfn(x) x * 2fn() doSomething()Dot shorthand for field access:
.name // fn(x) x.name.id != id // fn(x) x.id != id.done == false // fn(x) x.done == falseFunction Types
Section titled “Function Types”fn() -> () // takes nothing, returns nothingfn(string) -> number // takes string, returns numberfn(number, number) -> boolean // takes two numbers, returns boolean<Component prop={value}>children</Component><div className="box">text</div><Input /><>fragment</>Imports
Section titled “Imports”import { name } from "module"import { name as alias } from "module"import { a, b, c } from "module"
// Import for-block functions by typeimport { for User } from "./helpers"import { for Array, for Map } from "./collections"
// Mix regular and for-importsimport { Todo, Filter, for Array } from "./todo"Patterns
Section titled “Patterns”42 // literal"hello" // string literaltrue // boolean literalx // binding_ // wildcardOk(x) // variantSome(inner) // option{ field, other } // record destructure1..10 // range