Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Syntax Reference

This page summarizes the v0.0.1 syntax surface. The authoritative source is LANGUAGE_SPECIFICATION.md; this guide keeps examples practical and release oriented while identifying features that remain outside the release.

Temporal Affine Types are experimental and outside the default v0.0.1 gate. The v0.0.1 compiler supports the closed user enum slice described below.

Comments

// Single-line comment

/*
   Multi-line comment
*/

Literals

Literal forms follow the language specification. Use () for Unit values and the Unit type; Unit is not a supported type name.

val decimal: Int32 = 42
val hex: Int32 = 0xFF
val grouped: Int32 = 1_000_000

val ratio: Float64 = 3.14
val exponent: Float64 = 1.5e10
val negative_exponent: Float64 = 3.14E-2

val message: String = "ready\nnext"
val quote: String = "say \"ready\""
val mark: Char = 'a'
val newline: Char = '\n'

val enabled: Boolean = true
val disabled: Boolean = false
val done: () = ()

Bindings

Use val for immutable bindings:

val score = 42
val label: String = "ready"
val reading: Float64 = 21.5

Mutable bindings use mut val, with mut before val:

mut val counter = 0;
counter = counter + 1

Patterns can bind structured values:

record Point {
    x: Int32,
    y: Int32
}

fun sum_point: (point: Point) -> Int32 = {
    val Point { x, y } = point;
    x + y
}

Expression Boundaries

Line breaks are whitespace, so a direct OSV expression may continue on the next line. Values that cannot act as verbs naturally begin a new expression:

"first" println
"second" println

Use ; when a local binding is followed by an identifier-started expression that must not become another verb in the binding value:

val message = "ready";
message println

For a name used only inside a higher-order transformation, a scoped verb clause usually keeps the flow clearer and semicolon-free:

values map { |value|
    value + 1
}

Functions

Functions use fun name: (...) -> Type = { ... }.

fun add: (left: Int32, right: Int32) -> Int32 = {
    left + right
}

fun identity: <T>(value: T) -> T = {
    value
}

fun main: () -> Int32 = {
    (20, 22) add
}

Return types can be inferred for local functions when the body is clear:

fun double: (value: Int32) = {
    value * 2
}

Public Declarations

Use pub to expose a supported top-level declaration from a source module:

pub fun public_score: (value: Int32) -> Int32 = {
    value + 1
}

pub val release_bias: Int32 = 3
pub val no_payload: () = ()

pub enum exposes an enum type namespace to other Restrict source modules. It does not create a host-visible WebAssembly enum export.

For v0.0.1, top-level constants are limited to literal Int32, Int64, Float64, Boolean, Char, and () values. Exported String, records, lists, Option, Result, and user enum values require a composite host ABI or runtime allocation and are rejected by release-surface validation; create them inside functions instead.

OSV Calls

Restrict uses object-subject-verb call order. Arguments come before the function.

42 |> double
(10, 20) add
() make_default

Function-first calls such as add(10, 20) are not supported.

Lambdas

Lambda parameters are inferred from the expected function type:

fun apply_int: (f: Int32 -> Int32, value: Int32) -> Int32 = {
    value |> f
}

fun main: () -> Int32 = {
    (|x| x + 1, 41) apply_int
}

Standalone lambdas can provide parameter context with annotations:

fun main: () -> Int32 = {
    val bump = |value: Int32| value + 1
    41 |> bump
}

Scoped Verb Clauses

A callable whose final remaining parameter is a function can open that function as a scope:

val shifted = values map {
    it + 1
}

val total = (shifted, 0) fold { |sum, value|
    sum + value
}

The unheaded form introduces one contextual it binding. Explicit scope headers reuse lambda binders. A complete scoped clause is evaluated before a following clause or pipe.

See Higher-Order Functions and Collection Transforms for callback forms, collection behavior, inference, and affine captures.

Expressions

Supported operators include arithmetic, comparison, equality, and boolean operators:

val total = 1 + 2 * 3
val ready = total >= 7 && total != 0
val inverted = !ready

Conditionals use then:

score >= 80 then {
    "pass"
} else {
    "retry"
}

Pattern matching follows the value:

maybe_score match {
    Some(score) => { score }
    None => { 0 }
}

Records

Record declarations and literals use : for fields:

record Reading {
    celsius: Float64,
    ok: Boolean
}

fun main: () -> Float64 = {
    val reading = Reading { celsius: 21.5, ok: true };
    reading.celsius
}

Record updates use .clone { ... }:

fun mark_ok: (reading: Reading) -> Reading = {
    reading.clone { ok: true }
}

freeze is available for prototype-style immutable copies:

fun frozen_reading: (reading: Reading) -> Reading = {
    reading freeze
}

User-Defined Enums

The v0.0.1 slice supports closed, non-generic, non-recursive enums. Each variant has either no payload or one payload:

pub enum ParseError {
    Empty
    Message(String)
}

Constructors are qualified direct OSV call targets. Pass () to a payload-free variant and pipe the declared payload into a payload variant:

val empty = () ParseError::Empty
val invalid = "invalid input" |> ParseError::Message

Patterns are qualified too, and a match must cover every variant:

fun error_code: (error: ParseError) -> Int32 = {
    error match {
        ParseError::Empty => { 1 }
        ParseError::Message(message) => { 2 }
    }
}

Generic and recursive user enums, variants with more than one direct payload, first-class constructors, and a host enum ABI remain outside this slice.

Lists, Option, And Result

fun count_scores: () -> Int32 = {
    val numbers: List<Int32> = [1, 2, 3];
    val maybe_score: Option<Int32> = 42 Option::Some;
    val no_score: Option<Int32> = () Option::None;
    val success: Result<Int32, String> = 42 Result::Ok;
    val failure: Result<Int32, String> = "invalid" Result::Err;
    numbers |> list_count
}

Empty [] and () Option::None need context from an annotation, expected return type, or neighboring generic argument.

The example above uses local bindings. In v0.0.1, list, Option, and Result literals are not supported as top-level constants.

Context Blocks

Context declarations define available fields, and with Context { ... } { ... } binds values for a body:

context Policy {
    minimum_score: Int32
}

fun main: () -> Int32 = {
    with Policy { minimum_score: 80 } {
        minimum_score
    }
}

Imports

Imports use dotted source-module paths. Named and wildcard imports are current v0.0.1 syntax; string paths and aliases are reserved for a later module-design pass.

import release.policy.{score}
import release.policy.*

Precedence

The practical precedence order is:

  1. Qualified variant names such as ParseError::Message, field access, clone/freeze postfix forms, grouped OSV calls, and scoped verb clauses
  2. Unary - and !
  3. *, /, %
  4. +, -
  5. <, <=, >, >=
  6. ==, !=
  7. &&
  8. ||
  9. OSV calls and pipes
  10. Assignment in mutable bindings

Prefer parentheses when combining OSV calls with arithmetic or nested function values.