lang::construct

lang/src/construct.mo

defstr#
pub def str (s : String) : Term

A string literal.

defi64#
pub def i64 (n : I64) : Term

An I64 literal, printed with its i64 suffix.

defu32#
pub def u32 (n : I64) : Term
defu8#
pub def u8 (n : I64) : Term
defif_#
pub def if_ (cond : Term) (then_ : Term) (else_ : Term) : Term

if cond then then_ else else_, which is the surface spelling the printer writes back.

defcase#
pub def case (ctor : String) (args : List String) (body : Term) : MatchCase

One positional match arm: ctor args => body.

defmatch_#
pub def match_ (scrutinee : Term) (cases : List MatchCase) : Term

match scrutinee { cases }.

defvar#
pub def var (idx : I64) (name : String) : Term

A bound variable: idx is the de Bruijn index, name only what gets printed. Use Gen Env (motes/gen) rather than computing an index.

defglobal#
pub def global (name : String) : Term

A reference to a top-level name (U32.lt, Option.none): free, hence the sentinel index, printed exactly as written. A constructor prints with its type prefix (show_con), so a nullary one reads Option.none either way.

deflam#
pub def lam (name : String) (type_ : Term) (body : Term) : Term

fn (name : type_) => body.

defapp#
pub def app (fun : Term) (arg : Term) : Term
defapps#
pub def apps (fun : Term) (args : List Term) : Term
defcon#
pub def con (typ : String) (ctor : String) : Term

A nullary constructor: con "Option" "none" prints as Option.none.

defcon_app#
pub def con_app (typ : String) (ctor : String) (args : List Term) : Term

The same, applied: con_app "Option" "some" [x].

typeVis#
pub type Vis {
    vis_public,
    vis_private,
    vis_package,
}

Declaration visibility. Visibility is package-private, so a generator names one of these instead.

defparam#
pub def param (name : String) (type_ : Term) : Param

An ordinary (name : type) parameter.

defattr#
pub def attr (name : String) : Attribute

An attribute with no arguments, e.g. attr "partial" for #[partial].

defdef_text#
pub def def_text (attrs : List Attribute) (vis : Vis) (name : String)
(params : List Param) (ret : Term) (body : Term) : String

One declaration in the surface form a human writes:

#[partial]
pub def probe (cp : U32) : Bool :=
    if U32.lt cp 10u32 then true else false

params is the parameter list and body the body with those parameters already peeled, which is Def.params' shape -- not the Pi/lambda chain Def.typ/Def.term carry. def_of_text renders a parsed Def this way.

defdef_of_text#
pub def def_of_text (d : Def) : String

The same, for a Def a parser built: its params, and the result type and body recovered by peeling the Pi/lambda chain it folded them into.