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) = pair // tupleconst [first, second] = items // arrayconst { name, age } = user // recordFunction
Section titled “Function”fn name(param: Type) -> ReturnType { body}
// Generic function — type parameters after the namefn name<T>(param: T) -> T { body}
fn name<A, B>(a: A, b: B) -> (A, B) { body}
export fn name(param: Type) -> ReturnType { body}
async fn name() -> Promise<T> { await expr}// Recordtype User { name: string, email: string,}
// Union — positional ( ) or named { } fieldstype Shape { | Circle(number) | Rectangle(number, number) | Named { 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
// Newtypetype UserId(string)
// Opaqueopaque type Email(string)
// Deriving traitstype Point { x: number, y: number,} deriving (Display)Use (Callback Flattening)
Section titled “Use (Callback Flattening)”// Single binding — rest of block becomes callback bodyuse x <- doSomething(arg)doStuff(x)
// Zero bindinguse <- delay(1000)Console.log("done")
// Chaininguse a <- first()use b <- second(a)result(b)For Block
Section titled “For Block”for Type { fn method(self) -> ReturnType { body }}
for Array<User> { fn adults(self) -> Array<User> { self |> Array.filter(.age >= 18) }}trait Display { fn display(self) -> string}
// Trait with default implementationtrait Eq { fn eq(self, other: Self) -> boolean fn neq(self, other: Self) -> boolean { !(self |> eq(other)) }}
// Implement a traitfor User: Display { fn display(self) -> string { `${self.name} (${self.age})` }}Test Block
Section titled “Test Block”test "addition works" { assert add(1, 2) == 3 assert add(-1, 1) == 0}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 (_), array patterns ([first, ..rest]).
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 arraysmock<T> // generate test data from type, returns Tmock<User>(name: "Alice") // with field overridesQualified Variants
Section titled “Qualified Variants”Filter.All // zero-arg variantFilter.Active // zero-arg variantColor.Blue(hex: "#00f") // variant with data
// Required when variant name is ambiguous (exists in multiple unions)// Ok, Err, Some, None are always bare (built-in)Anonymous Functions (Closures)
Section titled “Anonymous Functions (Closures)”(a: number, b: number) => a + b(x: number) => x * 2() => doSomething()Dot shorthand for field access:
.name // (x) => x.name.id != id // (x) => x.id != id.done == false // (x) => x.done == falseFunction Types
Section titled “Function Types”() -> () // takes nothing, returns nothing(string) -> number // takes string, returns number(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"
// npm imports are unsafe by defaultimport { parseYaml } from "yaml-lib"const result = try parseYaml(input) // wraps in Result<T, Error>
// trusted imports skip the try requirementimport trusted { useState } from "react"
// Per-function trustimport { trusted capitalize, fetchData } from "some-lib"
// 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 // number literal"hello" // string literaltrue // boolean literalx // binding_ // wildcardOk(x) // variantSome(inner) // option{ field, other } // record destructure1..10 // range (inclusive)[] // empty array[only] // single-element array[first, ..rest] // array with rest"/users/{id}" // string pattern with captures_ when x > 10 // guard