Skip to content

Generics

Generic functions and structs with explicit instantiation at every call site.

Zmeu generics are explicitly instantiated: every generic call carries its type arguments at the call site. This keeps inference predictable and IR shapes stable.

def identity[T](value: T) -> T:
return value
def main() -> i32:
let x: i32 = identity[i32](1)
return x

The compiler monomorphises each instantiation; identity[i32] and identity[bool] produce separate, specialised functions.

def unwrap_or[T, E](r: Result[T, E], fallback: T) -> T:
let value: T = match r:
Ok(x) => x
Err(e) => fallback
return value

Call sites supply both arguments: unwrap_or[i32, bool](r, 0).

struct Box[T]:
value: T
impl Box[T]:
def get(self: view Box[T]) -> view T:
return view self.value

Generic struct methods use the surrounding impl’s type parameters after substitution.

  • Method-level type parameters (def method[T](...)) inside impl blocks
  • Trait/typeclass bounds
  • Higher-kinded constructs

These are deliberate deferrals: the language is staying simple until the rest of the surface settles.

Because every instantiation is explicit and monomorphised, generic code lowers to the same LLVM IR shape as a hand-written specialised version. The IR-count regression suite covers this: generic identity, generic Option unwrap, and generic Result.try all show zero overhead vs equivalent C.