Authoritative source: Syntax at a glance

Syntax at a glance

This appendix is a memory aid. The Language Reference remains normative.

Feature Canonical form
Module module App.Main;
Import import Core;
Filtered import import Core (Maybe, List);
Export export (main, Model);
Value value answer : Int = 42;
Function function add(x:Int,y:Int) : Int = x + y;
Lambda fn(x:Int) : Int = x + 1
Type parameter function id[a:Type](x:a) : a = x;
Constraint requires Eq(a), Show(a)
Sum data type Maybe(a:Type) = Nothing + Just * value:a;
Record-like data type Point = x:Float64 * y:Float64;
Tuple {1, True, "one"}
Structural record {name = "Ada", age = 36}
Let let x = 1 in x + 1
Conditional if condition then yes else no
Match `match item
Annotation expression : Type
Pi (n:Nat) -> Vec(a,n)
Sigma (n:Nat) * Vec(a,n)
Universal forall a. a -> a
Existential exists (a:Type). body
Unpack unpack item as (a,x) in body
Structure structure C(a:Type) = { ... };
Algebra algebra C(a:Type) = { ... };
Morphism morphism C(a:Type,b:Type) = { ... };
Instance instance C(Int) = { ... };
Law law name(x:a) = lhs === rhs;
Effect effect Console = { ... };
Action action main() : Eff { console:Console } Unit = { ... };
Handler handler H : E = { ... };
Install handler handle computation with H
Class class Animal(name:String) = { ... };
Construction Animal.new("Milo")
Repr repr Nat as Int where { ... };
Repr cast item as Int
Lazy expression ~expression
Target block target FastAccelerator { ... };

Semicolons separate declarations/statements; commas separate data.