Skip to content

Data and functions

Primitive data constraints

The standard library exposes compiler-provided primitive declarations through std::primitive. The current set includes:

ConstraintDescription
intDefault signed integer type
i8, i16, i32, i64Signed integer types
u8, u16, u32, u64Unsigned integer types
c_int, c_uintC-compatible integer types
boolBoolean data
strString data
IO AAn effectful computation producing A
ptr AA pointer to A

The standard library also defines data structures such as Nat, Option, Result, List, and Vec. See the standard-library reference.

Functions

Functions are ordinary terms. Lambda expressions use fun, and named definitions use def:

ligare
def add (left right : int) : int := left + right

def increment : int -> int := fun value => value + 1

Parameter lists are curried:

ligare
def add_one := add 1

Dependent arrows and parameter constraints can mention earlier parameters:

ligare
def increase (value : int) : int where (result => result >= value) :=
  value + 1

Generic and implicit parameters

Parameters in braces are inferred from context. A generic parameter is still a term constrained by prop:

ligare
def identity {A : prop} (value : A) : A := value

#check identity 42 : int

An explicit parameter such as A : prop can be used when callers need to choose the constraint directly.

Refinement constraints

Refinements describe a base constraint together with a predicate:

ligare
def NonZero : prop := int where (value => value /= 0)

def divide (left : int) (right : NonZero) : int := left / right

The compiler checks the predicate at each construction or call site. Proof arguments do not become runtime parameters.

Effects and do blocks

An IO A value is consumed in a do block. The standard library's I/O functions can be combined without exposing C details:

ligare
use std::io::print_line

pub def main : IO () :=
  do
    print_line 42

Calling an effectful value as pure data is rejected. FFI declarations use extern def; crossing the unsafe boundary is explicit with unsafe { ... }.