Types & contracts
A type is what a value is. Faber writes the type before the name, so you
read the kind of thing first. This page is the syntax of types and the
declarations that introduce new ones: interface is a contract of
methods, type is another name for an existing type, enum is a closed
set of named constants, union is a tagged choice with variants, and
schema describes relational columns.
Absence is a union, not a question mark. A missing integer is
i32 ∪ none; the missing value is null. There is no i32?. Widths are
bare markers — i32, f32 — written in type position.
Everyday types, type first:
main {
let string name ← "Marcus"
let i32 age ← 30
let bool flag ← true
let list<i32> nums ← [1, 2, 3]
let i32 ∪ none missing ← null
print name
print age
print flag
print nums
print missing
}A type alias is a transparent name. It does not create a new kind of
value:
type Signum = i32
type Nomina = list<string>
main {
let Signum signum ← 42
let Nomina sodales ← ["Gaius", "Lucius"]
print signum
print sodales
}Return to the grammar overview.
Terms#
These are the words you write in this part of the language. Each links to its page. The second column names the grammar rule the word belongs to.
| Term | Grammar rule |
|---|---|
interface | implendum_decl |
fn | implendum_method_decl |
type | typus_decl |
enum | ordo_decl |
union | discretio_decl |
schema | schema_decl |
column | schema_column |
ref, mut | union_hole_type |
ref, mut | owned_type |
record | ratio_type |
Formal grammar#
The rules for this part of the language are the parser's own definition of it. They are written for models and tools, so this page does not repeat them; the full list is at every production.