Documentation channel: current development main at compiler checkpoint 1d7e15e. The latest tagged release is v0.0.3; pages identify APIs that are not yet released.

Generics

Generic inference combines argument evidence with the expected result type. This means contextual expressions such as int[] empty := identity([]); work even though the empty literal alone has no element evidence. A standalone identity([]) is still diagnosed because neither side provides a concrete type.

Generic declarations use square brackets so generic parameters remain visually separate from instantiated types such as vector<T> or callable signatures.

Generic functions

function identity[T](T value) -> T {
    return value;
}

Multiple type parameters

function pair[X, Y](X first, Y second) -> Pair<X, Y> {
    return Pair<X, Y> { first: first, second: second };
}

Generic structs

struct Box[T] {
    T value;
}

Inferred generic lambdas

Undeclared all-uppercase type identifiers in lambda parameter types are inferred as generic parameters. Misspelled lowercase or mixed-case types remain compiler errors.

max := (T a, T b) => {
    if (a > b) { return a; }
    return b;
};

Explicit generic lambda type

When the callable contract itself matters, write the generic function type explicitly.

function[T]<(T, T) -> T> max :=
    (a, b) => {
        if (a > b) { return a; }
        return b;
    };

Why uppercase generic names?

The convention is part of the language rather than a style preference. T, X, and VALUE can identify generic parameters; a typo such as ddouble is therefore diagnosed as an unknown type instead of silently becoming a generic.

Contextual and nested inference

The following example is compiled and run by the documentation certification suite. Inference recursively unifies arrays and nullable types rather than treating the outer generic as an opaque string.

function identity[T](T value) -> T {
    return value;
}

function nested[T](T[] values) -> T[] {
    return values;
}

function main() -> int {
    int[] empty := identity([]);
    int[][] matrix := nested([[1], [2]]);
    int? maybe := identity(7);
    println(empty.length);
    println(matrix.length);
    println(maybe ?? 0);
    return 0;
}