Skip to main content
v0.13.0

Type System

Metel is statically and strongly typed. Types are checked at compile time. There are no implicit conversions.

Primitive Types

TypeDescriptionExample
i6464-bit signed integer42
f6464-bit floating point3.14
booleanBooleantrue
StringUTF-8 string"hello"
CharUnicode scalar value'a'
()Unit — represents no value()

The unit type () is only written explicitly when needed as a type parameter (e.g. Result<(), Error>). Functions that return nothing omit the -> annotation entirely.

Sized Numeric Types

Sincev0.8.0

Metel provides exact-width numeric types for low-level and systems programming. i64 and f64 are the default integer and floating-point types in ordinary code.

Signed integers:

TypeWidth
i88-bit
i1616-bit
i3232-bit
i6464-bit

Unsigned integers:

TypeWidth
u88-bit
u1616-bit
u3232-bit
u6464-bit

Floats:

TypeWidth
f3232-bit IEEE 754
f6464-bit IEEE 754

Sized literals use a suffix: 42i32, 3.14f32, 255u8. All casts between sized numeric types are explicit (as). Array indices must be u64; indexing with an i64 requires an explicit as u64 cast.

Unsuffixed literals are polymorphic. When the expected type is known from context (annotation, function parameter, struct field, return type, or the other operand in arithmetic/comparison), an unsuffixed numeric literal adopts that type automaticallyL3. When no context is available, the literal defaults to i64 (integer) or f64 (float).

let a: i32 := 10; // 10 is i32
let b: u8 := 255; // 255 is u8
let c: f32 := 1.5; // 1.5 is f32

fun scale(x: f32, factor: f32) -> f32 { x * factor }
let r := scale(2.0, 3.0); // both literals are f32

let x: i32 := 10i32;
let y := x + 5; // 5 adopts i32 from x; y is i32

This also applies to var reassignment — the right-hand side of m := expr adopts m's declared type:

var count: i32 := 0;
count := 99; // 99 is i32
Formal rules
Legality Rule №1

The exact-width numeric primitive types are i8, i16, i32, i64, u8, u16, u32, u64, f32, and f64.

Referenced by: rfc-0007

Legality Rule №2

Conversion between numeric types is written with an explicit as cast.

Referenced by: rfc-0007

Legality Rule №3

An unsuffixed numeric literal adopts the numeric type supplied by context; without context, integer literals default to i64 and floating-point literals to f64.

Referenced by: rfc-0007

Dynamic Semantics №1

Integer overflow panics, unconditionally — Metel has no debug/release build-mode distinction of its own (the interpreter takes no such flag), so this applies the same way regardless of how the interpreter binary happens to have been compiled. Floating-point overflow follows IEEE 754 behavior.

Referenced by: rfc-0007

Char

Sincev0.8.0

Char represents a single Unicode scalar value. Character literals use single quotes: 'a', '\n', '\u{1F600}'.

fun main() {
let c: Char := 'a';
let code: u32 := u32::from(c);
let back: Char := Char::from(code);
}

Char is not u32 and not a string — no implicit coercions exist. Use u32::from(c)Char methods D1 to get the Unicode scalar value and Char::from(n)Char methods D1 to construct from a code point; Char::from raises a runtime error if n is not a valid Unicode scalar value.

Formal rules
Legality Rule №1

Char is a distinct Unicode-scalar type, not an alias for u32 or u8.

Referenced by: rfc-0007

Type Inference

Types are inferred using the Hindley-Milner algorithm with let-polymorphism. Annotations are optional for all bindings, including function parameters and return types. They may be written explicitly for documentation or to restrict a binding to a less general type.

Annotations are required only where there is no expression to infer from:

  • Struct and enum field types
  • Aspect method signatures

Every named type in an annotation must resolve in the annotation's declaring scope, including names nested inside arrays, tuples, function types, and record fields. This is checked when the declaration is type-checked, even if no value ever reaches the annotation. A generic parameter in scope and Self where it is permitted resolve as types; every other unknown name is error T0003.

fun add_annotated(a: i64, b: i64) -> i64 { a + b }
fun add_inferred(a, b) { a + b }

fun main() -> i64 {
let x := 42; // inferred: i64
let name := "Vlad"; // inferred: String
let y: f64 := 3.14; // explicit annotation (optional here)
let total := add_annotated(x, 1) + add_inferred(2, 3);
if (name == "Vlad") { total + (y as i64) } else { 0 }
}
Formal rules
Legality Rule №1

An expression in return position is typechecked against the enclosing function or method's declared return type, which supplies its expected type.

Referenced by: rfc-0019

Legality Rule №2

An expression in break position is typechecked against its enclosing loop's value type, independently of the enclosing function's return type.

Referenced by: rfc-0019

Tuples

Tuples are lightweight anonymous product types.

fun main() -> i64 {
let coord: (i64, i64) := (10, 20);
let triple: (String, i64, boolean) := ("yes", 42, true);
return coord.0 + triple.1;
}

Positional field access uses zero-based selectors .0, .1, etc.L1:

fun main() -> i64 {
let coord: (i64, i64) := (10, 20);
let x := coord.0;
let y := coord.1;
return x + y;
}

() is the zero-element tuple (unit type).

Tuples can be destructured in match:

fun main() -> i64 {
let coord: (i64, i64) := (10, 0);
match (coord) {
(0, y) => y,
(x, 0) => x,
(x, y) => x + y,
}
}
Formal rules
Legality Rule №1

A tuple's elements are addressed by zero-based positional selectors. A selector is valid only for an element in the tuple's declared arity.

Tested by (2)

Anonymous Records

Sincev0.12.0

A record is a product type whose components are labelled, where a tuple's are positional. It is written in bare braces, with no keyword:

{ x: f64, y: f64 } // the type
{ x = 1.0, y = 2.0 } // a value of it

Field declarations classify and take :; field initializers define and take = — the same distinction let x: i64 = 1 already draws.

A record type is exact. { x: f64 } is inhabited only by records with that row and nothing else; a value of { x: f64, y: f64 } is not a value of { x: f64 }. Records are not implicitly widened or narrowed.

Records are structurally typed. Two records with the same labels and field types are the same type, wherever they were written. A record has no declaration site and no name. Field order does not matter: { x: i64, y: i64 } and { y: i64, x: i64 } are the same type, and { x = 1, y = 2 } and { y = 2, x = 1 } are indistinguishable — each is usable wherever the other is. A record is a set of labelled fields, not an ordered one. Repeating a label in one record ({ x: i64, x: f64 }) is an error.

(Indistinguishable is a statement about the type, not about ==, which no compound type — record, struct, tuple, or array — supports.)

When a local variable has the same name as a field, the = value part may be omitted, as in a struct literal:

fun main() {
let x := 1.0;
let y := 2.0;
let p := { x, y }; // { x: f64, y: f64 }
println("${p.x}");
}

Punning, and single-field record literals generally, are read as records only in positions that expect an expression — a let/var or field initializer, a call argument, an array element. In a position that also admits a block — an if/else or match arm, a function, closure, or loop body — a bare { x } is a block whose result is x, and { x = 1 } is a block whose result is the assignment. Write the record in parentheses to force it: ({ x }). A multi-field literal needs no parentheses, as { x = 1, y = 2 } cannot be a block.

Where records may be used

Records are ordinary values: they may appear as parameters, returns, let bindings, and struct or enum fields; they may be pattern-matched, used as generic arguments, and borrowed (&{ x: f64 }) exactly as a struct is. Send and Sync extend to them by the same field-composition rule used for structs.

Three things a record cannot do, all for the same underlying reason — it has no nominal owner:

  • No inherent methods. Two unrelated modules could otherwise write conflicting methods for the same shape with no principled way to choose between them.
  • No implementations of a non-local aspect, by the other direction of that rule. An aspect local to the current module may be implemented for a record — but see the note below: that is not available yet.
  • No custom Drop. Drop is a standard-library aspect and never local to ordinary user code, so teardown logic belongs to nominal types only.
Planned forv0.14.0RFC-0061metel-core#239implementing a local aspect for a record or tuple target. Until then, extend { w: i64 }: MyAspect { … } does not work. Arrays are the exception: extend<T> T[]: MyAspect { … } is supported, per the orphan-rule carve-out for structural type constructors — see Declarations — Structural Aspect Bounds. Until a record or tuple target is supported, a record satisfies no aspect that requires an implementation, so a record cannot be printed, compared, or passed where any such bound is required. Auto-derived aspects are unaffected

Projection

A nominal type's row may be projected to a named subset, written with a dot to distinguish it from a struct literal:

Handle.{ fd } // the type: Handle's row, narrowed to `fd`

A bare identifier inside projection braces is always a field label, never a type or a row variable. Chained projection (S.{ a }.{ b }) and projection in pattern position are not accepted.

Inside an extend block, Self.{ fd } projects Self's own row exactly as Handle.{ fd } would project Handle's — Self resolves to the enclosing block's target type here the same way it does everywhere else the target's name can stand in for it.

Formal rules
Dynamic Semantics №1

Record identity is structural: records with the same labelled fields and field types are the same type regardless of declaration-free spelling order.

Referenced by: rfc-0116

Legality Rule №1

An anonymous record cannot satisfy an impl-based aspect bound, because no implementation for a record target is available.

Referenced by: rfc-0116

Dynamic Semantics №2

Projection Handle.{ fd, mode } yields the record made from precisely the named fields of the nominal receiver type.

Referenced by: rfc-0116

Tested by (3)
Legality Rule №3

An anonymous record is rejected as an inherent-implementation target, as the target of a non-local aspect implementation, and as the target of a custom Drop implementation.

Referenced by: rfc-0116

Tested by (3)

Arrays

Array<T> is the built-in ordered sequence type. The shorthand T[] is preferred.

fun main() -> i64 {
let nums: i64[] := [1, 2, 3];
let names: Array<String> := ["alice", "bob"];
if (names.len() == 2) { nums[0] } else { 0 }
}

Index access uses [] with a u64 index. Out-of-bounds access causes a panic.

fun main() -> i64 {
let nums: i64[] := [1, 2, 3];
let first := nums[0];
return first;
}

Arrays are usable in for-in loops.

Changed inv0.12.0RFC-0126T[] is no longer an owning, mutable buffer

T[] is a non-owning, immutable, unconditionally-Copy view over a contiguous run — a pointer and a length — produced only by borrowing a List<T>, a [T; N], or another slice. Assignment through a slice, such as a[0] = 9, does not compile; mutation belongs to List<T> or [T; N]. Array literals produce [T; N] (below), not T[]; let nums: i64[] = [1, 2, 3]; continues to work through [T; N]'s implicit coercion to T[] (RFC-0053), not because the literal itself is a T[].

The three-way split between T[], [T; N], and List<T> below reflects the current design. The exact boundary between them — in particular, how a growable list's storage is allocated and grown — is not yet fully specified and may change in a future release.

Formal rules
Legality Rule №1

T[] is an unconditionally-Copy, non-owning borrowed view. It has no Drop; using a view does not move the underlying elements out of the view.

Referenced by: rfc-0061, rfc-0071, rfc-0126

Tested by (4)
Legality Rule №2

An array index expression must have type u64.

Referenced by: rfc-0007

Fixed-size arrays

SinceFixed-size arraysv0.8.0

[T; N] is an array type whose length N is a non-negative integer literal known at compile time. [T; N] coerces to T[] (not the reverse). N must be a non-negative integer literal; variables are not permitted.

fun main() {
// Repeat construction: every element is the same value.
let zeros: [i64; 3] := [0; 3];

// Literal construction with an explicit sized type.
let ones: [i64; 3] := [1, 2, 3];

// Coerces to T[] when a T[] is expected.
fun first(xs: i64[]) -> i64 { xs[0] }
let v := first(ones); // [i64; 3] → i64[]
}

Indexing and for-in work identically to T[]. Array patterns match sized arrays:

fun sum(xs: [i64; 3]) -> i64 {
match (xs) {
[a, b, c] => a + b + c, // exact-count pattern on [T; 3]
}
}
Changed inv0.12.0RFC-0126unannotated array literals now have [T; N], not T[]

An unannotated literal such as [1, 2, 3] has type [i64; 3]: its length is statically known and it owns its elements. Slices arise only from borrowing, never from a literal. The [T; N]T[] coercion above applies wherever T[] is expected — a let/var target, a function argument, or a generic instantiation — so existing call sites need not change when they already accept a [T; N]-typed or explicitly T[]-annotated value. Only an unannotated literal's own type changed.

See the note under "Arrays" above — this split is not considered final.

Formal rules
Legality Rule №1

An array literal has fixed-size-array type [T; N], not T[], where N is its literal element count.

Referenced by: rfc-0126

Legality Rule №2

[T; N] implicitly coerces to T[] wherever T[] is expected. The reverse coercion is not permitted.

Referenced by: rfc-0053, rfc-0126

Tested by (3)
Legality Rule №3

[T; N] is a fixed-size-array type only when N is a non-negative integer literal; the element type and literal length both participate in type identity, including for [T; 0].

Referenced by: rfc-0053

Tested by (4)
Dynamic Semantics №1

A repeat array expression [expr; N] evaluates expr once, then clones that result to produce all N elements.

Referenced by: rfc-0053

Legality Rule №4

Where [T; N] is expected, an array literal is accepted only when it contains exactly N elements of type T.

Referenced by: rfc-0053

Tested by (3)
Legality Rule №5

A fixed-size array type [T; N] is valid as a struct field type.

Referenced by: rfc-0053

Legality Rule №6

A fixed-size array may have another fixed-size array as its element type, such as [[i64; 2]; 2].

Referenced by: rfc-0053

Legality Rule №7

An exact array pattern for a [T; N] value must have a compatible element count; a different exact count is rejected.

Referenced by: rfc-0053

Tested by (3)
Legality Rule №8

The length in [T; N] is an integer literal, not a named generic type parameter or an arbitrary runtime expression.

Referenced by: rfc-0053

Legality Rule №9

Every literal index into [T; 0] is statically rejected because it is out of bounds.

Referenced by: rfc-0053

References

Sincev0.10.0

Reference types provide explicit aliasing.

fun main() -> i64 {
var value := 1;
let p: &i64 := &value;
let q: &var i64 := &var value;
*q := *p + 1;
return q;
}

Metel has two reference types:

  • &T — shared immutable reference to T
  • &var T — exclusive mutable reference to T
Planned forv0.16.0RFC-0122shared XOR exclusive — a place may have any number of &T borrows, or exactly one &var T, never both

"Exclusive" means exactly that rule. It is not yet enforced: the current interpreter has no borrow checker, so a program may hold two &var T to the same place and will not be rejected.

&var T coerces to &T. The reverse coercion does not exist. Both are non-owning aliases — a reference never owns the value it points to.

&T is Copy; &var T is not, so an exclusive reference is moved on use rather than duplicated. Passing one as an argument reborrows instead of moving — see §References and moves.

References are first-class values, but they are distinct from the referent type. Ordinary access — field reads/writes, indexing, method dispatch, reading a plain value out — goes through auto-deref and type-directed copy; an explicit dereference operator *p is also available (v0.11.0) for reading through a reference and for writing through a &var T (*p = v). See §References.

&var accepts arbitrary addressable lvalue paths — struct fields, tuple elements, array elements, and chains thereof. Writes through the resulting &var T propagate back to the original storage location:

struct Counter { value: i64 }

fun main() -> i64 {
var c := Counter { value = 0 };
let p: &var i64 := &var c.value;
*p := 42;
return c.value; // 42
}
Since&var for lvalue pathsv0.10.0
Formal rules
Legality Rule №1

An &var T reference may be used where &T is expected; an &T reference may not be used where &var T is expected.

Referenced by: rfc-0067a

Reading a value out of a reference

No field, no method, no operator — just the plain value a reference points to. This cannot be a move (references never own their referent), only a copy, and only when the referent's type permits copying:

fun main() -> i64 {
let x := 42;
let r: &i64 := &x;
let y: i64 := r; // type-directed copy: y's declared type differs from r's
return y;
}

The copy fires at every position where a declared or expected type is already known — not only let/var bindings and explicit ascription, but also a return value against the enclosing function's declared return type, a break value against the enclosing loop's inferred type, and any tail expression of a function/method/ closure body, an if/else branch, or a match arm (each of those resolves its result against a declared or expected type the same way a let binding does):

fun bump(p: &var i64) -> i64 {
*p += 1;
p // tail expression, no explicit `return` — copies out of p
}

It never fires silently at a plain call site; fun f(v: i64) called as f(r) where r: &i64 is a type error, not an implicit copy. Argument position has no declared type of its own for the rule to compare against, the same reason type-directed extraction of an allocated value never fires implicitly at a plain-parameter call site either (public/rfcs/2-accepted/rfc-0066-allocated-value-extraction.md §3a — not yet integrated, cited here only for the parallel).

Chains through multiple reference layers the same way auto-deref does — reaching the declared type may require copying out of more than one layer:

fun main() -> i64 {
let x := 42;
let r: &i64 := &x;
let rr: &&i64 := &r;
let y: i64 := rr; // copies through both layers of the chain
return y;
}

Until affine ownership (Copy/Drop, not yet integrated) lands, this applies to every type — the interpreter has no move semantics today (everything is deep-cloned on bind), so there is no non-Copy type yet to exclude. Once ownership is integrated, a non-Copy T cannot be produced this way.

Formal rules
Legality Rule №1

Where a declared or expected non-reference type is known, a reference expression may copy out its referent through every reference layer only when the referent is Copy. This applies to bindings, ascriptions, returns, breaks, and tail expressions, but not to an un-ascribed call argument.

Referenced by: rfc-0067a

Tested by (8)

List<T>

Sincev0.8.0

List<T> is the standard growable-sequence type. Use it when you need to append, pop, or otherwise mutate a sequence. Use T[] when the sequence is fixed after construction.

fun main() {
var xs: List<i64> := List::new();
xs.push(1);
xs.push(2);
xs.push(3);
println(xs.len().to_string()); // 3
let last := xs.pop(); // Some { value = 3 }
}

Construction:

FormDescription
List::new()Empty list
List::from(arr)Construct from a T[] — copies elements

Methods:

MethodSignatureDescription
push(&var self, value: T)Append an element
pop(&var self) -> Perhaps<T>Remove and return the last element, or None
len(&self) -> i64Number of elements
get(&self, index: i64) -> Perhaps<T>Bounds-checked access
as_slice(&self) -> T[]View as an immutable array (no copy)

List<T> does not implicitly coerce to T[]. Call .as_slice() to get a read-only view.

Changed inv0.12.0RFC-0126as_slice returns a live borrowed view rather than a copied result

as_slice returns the same underlying storage, and the result remains a view for as long as it is used, bounded by self's lifetime. "No copy" therefore describes the value's full lifetime, not only the call itself.

Formal rules
Dynamic Semantics №1

List::new() creates an empty list, and List::from(source) creates a list containing the elements of source.

Referenced by: rfc-0054

Dynamic Semantics №2

push appends an element; pop removes and returns the last element, or None for an empty list.

Referenced by: rfc-0054

Dynamic Semantics №3

len reports the list's current number of elements, including changes made by push and pop.

Referenced by: rfc-0054

Dynamic Semantics №4

get(i) returns Some for an in-bounds element and None when i is out of bounds.

Referenced by: rfc-0054

Legality Rule №1

A List<T> is distinct from T[]; obtaining its array view requires an explicit .as_slice() call.

Referenced by: rfc-0054

Type Ascription

Sincev0.2.0

The : operator asserts that an expression has a given type without performing any runtime conversionL1. It is a pure type-inference hint — no code is emitted at runtime.

Type ascription is mainly an ergonomics feature. Most code should type-check from its surrounding context alone; : is for the cases where spelling out the intended type inline is clearer than introducing a separate annotated binding.

fun main() -> i64 {
let xs := [] : i64[];
let x := 1 : i64;
if (xs.len() == 0) { x } else { 0 }
}

Ascription fails at compile time if the inferred type of the sub-expression cannot be unified with the ascribed typeL2. For example, 1 : String is invalid. Use as to convert between types; use : only when the value already has the target type.

fun main() -> i64 {
let y := 1 : String;
return 0;
}
Formal rules
Legality Rule №1

expr : T constrains expr to type T and supplies T as its expected type; it performs no runtime conversion.

Referenced by: rfc-0021, rfc-0023

Tested by (2)
Legality Rule №2

An ascription is valid only when the expression's type unifies with the ascribed type; otherwise it is a type error.

Referenced by: rfc-0021

Legality Rule №3

An expression may contain at most one type ascription; a second : in the same ascription position is a parse error.

Referenced by: rfc-0021

When ascription helps

Type inference uses surrounding expected types. That expected type can come from a let annotation, a function return type, a callee's parameter types, or the surrounding expression context.

Because of that, ambiguous literals like [] and None often type-check without explicit ascription when the context already determines their type:

fun zip_lengths(a: i64[], b: String[]) -> i64 {
return a.len() + b.len();
}

fun make_row(use_default: boolean, fallback: i64[]) -> i64[] {
return match (use_default) {
true => [],
false => fallback,
};
}

fun first_or_default(items: i64[], fallback: Perhaps<i64>) -> i64 {
return match (fallback) {
Some { value } => value,
None => if (items.len() > 0) { items[0] } else { 0 },
};
}

fun main() -> i64 {
let total := zip_lengths([], ["a", "b"]);
let row := make_row(true, [1, 2, 3]);
let first := first_or_default([1, 2, 3], None);
return total + row.len() + first;
}

Ascription is still useful when no surrounding context fixes the type:

fun main() -> i64 {
let arr := [] : i64[];
let value := None : Perhaps<i64>;
match (value) {
Some { value } => value + arr.len(),
None => arr.len(),
}
}

Without such context, ambiguous literals remain a type error. For example, let x = None; does not provide enough information to infer the element type.

fun main() -> i64 {
let x := None;
return 0;
}

Type Casting

The as operator performs an explicit conversion from expr's type to TD1. It desugars to a call to the From aspect and is infallible — the result is the target type directly.

fun main() {
let x: i32 := 1000i32;
let b: i8 := x as i8; // wraps: 1000 mod 256 → -24
let f: f32 := x as f32; // 1000.0f32
let u: u64 := x as u64; // 1000u64

let pi: f64 := 3.14;
let n: i32 := pi as i32; // truncates toward zero → 3
}

All pairwise casts among i8, i16, i32, i64, u8, u16, u32, u64, f32, f64 are supported. Narrowing integer casts wrap (two's-complement truncation). f64-to-integer casts truncate toward zero.

Because as desugars to From, user-defined types become castable by implementing From<SourceType> for the target type.

Formal rules
Dynamic Semantics №1

expr as T evaluates an explicit conversion of expr to T via From<S>::from (where S is expr's type) and produces a value of type T. Not restricted to numeric types — any type with an applicable From<S> implementation is a valid cast target.

Referenced by: rfc-0021

Generics

SinceBuilt-in generic types (Perhaps<T>, Result<T, E>, T[])v0.1.0User-defined generic functions and typesv0.3.0

Types and functions can be parameterized with <T> syntax.

struct Stack<T> {
items: T[],
}

fun first<T>(arr: T[]) -> Perhaps<T> {
if (arr.len() == 0) {
return None;
}
return Some { value = arr[0] };
}

fun main() -> i64 {
let stack := Stack { items = [1, 2, 3] };
match (first(stack.items)) {
Some { value } => value,
None => 0,
}
}

Row bounds

Sincev0.12.0

A bound written as a row accepts any type carrying at least the listed fields:

fun squared_magnitude<record T: { x: f64, y: f64, .. }>(p: T) -> f64 {
p.x * p.x + p.y * p.y
}

The trailing .. is load-bearing. It stands for "and a rest I am not naming," and its presence is what makes the bound open:

fun g<record T: { x: f64 }>(p: T) // closed: T's row is exactly `x`
fun h<record T: { x: f64, .. }>(p: T) // open: T has at least `x`

A record pattern's own trailing .. reads the bound's listed fields the same way field accessL6 does, and — unlike field access — can discard the rest of an open bound's unlisted fields rather than being unable to name them at all:

fun describe<record T: { x: f64, .. }>(p: T) -> String {
match (p) {
{ x, .. } => "x is ${x}, plus whatever else the caller passed",
}
}

The .. is required to match an open bound at all — its full field set isn't known here, so a pattern that doesn't end in .. can never be exhaustive:

fun bad<record T: { x: f64, .. }>(p: T) -> f64 {
match (p) {
{ x } => x, // error: open bound's field set isn't known here; add `..`
}
}

A closed bound's fields are fully known, so .. there is optional sugar rather than a requirement — a pattern matching a closed bound must still name every field the bound lists unless it uses ..:

fun get_x<record T: { x: f64, y: f64 }>(p: T) -> f64 {
match (p) {
{ x, y } => x, // OK: every field of the closed bound is named
// { x } => x, // error: `y` isn't named and there's no `..`
}
}

Naming a field the bound doesn't list is still rejected, .. or not — the pattern's rest form discards unnamed fields, not fields the bound never promised are there:

fun bad2<record T: { x: f64, .. }>(p: T) -> f64 {
match (p) {
{ x, z, .. } => x, // error: no field `z` on the bound
}
}

A field may omit its type to constrain the label only — { x } means "carries an x, whatever its type":

fun f<record T: { x, .. }>(p: T) // has an `x` of some type
fun g<record T: { x, y: f64, .. }>(p: T) // any-typed `x`, `f64` `y`

Negation reuses the ! that bounds already accept, and is the complement of the positive bound — just as !Copy means "does not implement Copy". It takes no .., since absence has no rest to quantify over:

fun send<record T: !{ token }>(t: T) -> i64 {} // carries no `token` at all
fun tag<record T: !{ id: String }>(t: T) -> i64 {} // no `String`-typed `id`

Note the second form is satisfied by a record whose id is an i64 — it does not have a String id. Write !{ id } for "no id of any type".

A row bound is satisfied by a record, not by a nominal struct. The record marker on the type parameter says so at the declaration; a bare <T: { … }> is an error.

The marker may be written at the parameter or in a where clause — the two are equivalent, and a parameter is record-kinded if either one carries it:

fun f<record T: { x: f64, .. }>(p: T) -> f64
fun g<T>(p: T) -> f64 where record T: { x: f64, .. }

The row bound is optional. <record T> on its own means "any record, whatever its fields" — the only way to write that, since a bound of { .. } alone is not accepted:

fun labels<record T>(x: T) -> Symbol[] // any record; no constraint on its fields
squared_magnitude({ x = 3.0, y = 4.0 }); // a record — satisfies the bound
squared_magnitude(some_point); // a struct — does not

Nominal structs do not satisfy row bounds. Named records are planned, not implemented; they would provide a nominal record kind. See public/rfcs/2-accepted/rfc-0120-named-records.md (RFC-0120: Named Records) — a plain path mention rather than a link while rfcs/ is excluded from the website (see metel-website's docusaurus.config.ts), so this doesn't become a broken link once RFCs sync through.

Why row capability is opt-in

A nominal type's API is what it declares. An anonymous record's API is what it contains.

Once a type satisfies row bounds, its field names and types are part of its public interface, whether the author intended that or not. Renaming a field breaks every caller who wrote a bound mentioning it; adding one can make the type accidentally satisfy a bound its author never heard of. On a struct, a field rename is an internal change.

That is why structural capability is opt-in rather than automatic:

encapsulationstructural flexibility
structlayout is private; the API is what you declarenone

Most types want the first. A value whose shape is genuinely the contract — a coordinate pair or a configuration fragment — can use an anonymous record.

What satisfies which bound

Both bound kinds are opted into; they differ only in granularity. An aspect bound is opted into per aspect, by writing an implementation. A row bound is opted into per type, by choosing the record kind. Nothing is implicit in either direction.

Sincev0.13.0RFC-0137metel-core#857a plain struct's row is not visible to row-bound satisfaction

Every struct is represented internally as (brand, row) (see Ownership — Narrowing§Narrowing). The table's "no" is a visibility gate, not the absence of a row: a plain struct's row is never visible to row-bound satisfaction, regardless of narrowing or projection — including at full width, where its content is identical to a same-shaped record's. This preserves the same observable outcome as before, expressed on the branded-row mechanism itself.

non-local aspect (Display)local aspectrow bound
structyes, with an implyes, with an implno
enumyes, with an implyes, with an implno — sums, not products
anonymous recordno — see belowyes, with an implyes

An anonymous record has no owning module, so the orphan rule permits an implementation only for an aspect local to the implementing module. Every standard-library aspect is non-local, which means no anonymous record is Display and println("${r}") does not work on one. Auto-derived aspects are unaffected — Send and Sync are computed from field composition rather than declared.

Implementing an aspect for a record

Three forms, with different rules:

extend { x: f64, y: f64 }: MyAspect {} // one concrete row
extend<row R: { x: f64, .. }> { ..R }: MyAspect {} // every row of a given shape
extend<row R> { ..R }: MyAspect {} // every row

None of the three are available in v0.12.0 — this contradicted the "Not available in v0.12.0" callout above until corrected here; confirmed directly, extend { x: f64, y: f64 }: MyAspect { … } still fails with the same "cannot extend an anonymous record type" rejection tuples and records both hit. The first form is the one this design intends to land first — exactly one structural type, permitted once the aspect is local — but it is not implemented yet, unlike the equivalent one-concrete-target form for arrays (extend<T> T[]: Aspect, already supported). The second and third additionally require row variables, which don't exist at all yet. The second also needs overlap checking between row bounds — two shape-conditional implementations can be incomparable rather than one being more specific, so they must be disjoint. The third additionally needs a way to require an aspect of every field in the row, which does not yet exist either.

Formal rules
Legality Rule №1

A row bound requires record on its type parameter, either at the parameter declaration or in a where constraint; record without a row bound is also a legal any-record bound.

Referenced by: rfc-0118

Tested by (2)
Legality Rule №2

A negative row bound is satisfied only when none of its named fields match; it accepts no trailing .. and a negative bound in a where clause is enforced like an inline one.

Referenced by: rfc-0118

Tested by (3)
Legality Rule №3

A field in a row bound may omit its type, constraining the field label while accepting any field type.

Referenced by: rfc-0118

Tested by (2)
Legality Rule №4

Only a record satisfies a row bound; a nominal struct is rejected even when it has matching fields.

Referenced by: rfc-0118

Tested by (2)
Legality Rule №5

Brace syntax after a parameter or let annotation denotes an exact record type, while the same syntax in a generic parameter or where constraint denotes a row bound.

Referenced by: rfc-0118

Legality Rule №6

A field a row bound lists is accessible via field access (p.x) from inside the function body; a field the bound doesn't list is not, even when a caller's concrete argument happens to carry it.

Legality Rule №7

A record pattern's trailing .. binds only the fields it names against a row-bounded type parameter and discards the rest, the same as it does against a named struct. It is required to match an open bound at all, since the bound's full field set isn't known; for a closed bound it is optional, but the pattern must otherwise name every field the bound lists. Naming a field the bound doesn't list is rejected regardless of ...

Tested by (4)

Never Type

Sincev0.10.0

! (Never) is the uninhabited bottom type — no value of type ! can ever be constructed. A loop with no reachable break has type !:

fun main() -> i64 {
let result: i64 := loop { break 42; };
return result;
}

return <expr>, panic(<message>), loop { } with no reachable break, and break/continue used as value expressions in loop context all have type !. If any sub-expression has type !, that sub-expression diverges before the outer expression can produce a value, so the outer expression's type is unconstrained and any type is accepted in that position.

Subtyping and coercion

! is a subtype of every type — ! <: T for all T — so an expression of type ! coerces implicitly, with no cast, to any context expecting T. This is what makes the rule above sound: code after a diverging expression is unreachable, but still typechecks against whatever its context requires.

Match exhaustiveness

A match whose scrutinee has type ! needs no arms — an empty match is vacuously exhaustive, since no value of type ! can ever reach it:

fun unreachable_code(x: !) -> i64 {
match x { } // exhaustive — no arms needed
}

More generally, an enum variant whose payload type is ! is uninhabited — no value of that variant can ever be constructed — and a match may omit the arm for an uninhabited variant while remaining exhaustive:

enum Foo {
A { x: i64 },
B { y: ! },
}

fun handle(f: Foo) -> i64 {
match (f) {
Foo::A { x } => x,
// Foo::B omitted — exhaustive; B is uninhabited
}
}

Inhabited-singleton coercion

If an enum has exactly one inhabited variant (every other variant's payload is !) and that variant has exactly one field, a value of the enum type coerces implicitly to the field's type — the compiler inserts the destructuring, no explicit match required:

enum Wrapper<T> {
Present { value: T },
Absent { _: ! },
}

fun infallible() -> Wrapper<i64> { Wrapper::Present { value = 42 } }

fun main() -> i64 {
let x: i64 := infallible(); // implicit coercion via the inhabited-singleton rule
return x;
}

Result<T, !> satisfies this: Ok { value: T } is the one inhabited variant with one field, so a Result<T, !>-returning function's caller can use the result as a plain T with no match. Perhaps<!> does not satisfy it — None is inhabited but has zero fields — so Perhaps<!> never coerces implicitly to anything, though nothing prevents it from arising through generic instantiation.

! as a return type

A function annotated -> ! promises never to return; every control-flow path must end in a diverging expression, checked by the compiler:

fun abort(msg: String) -> ! {
panic(msg);
}

A -> ! function containing a reachable return is a type error.

Formal rules
Legality Rule №1

! is uninhabited: no terminating expression can construct a value of that type.

Referenced by: rfc-0078

Legality Rule №2

! is a subtype of every type, and an expression of type ! implicitly coerces to any expected type.

Referenced by: rfc-0078

Legality Rule №3

Code made unreachable by a diverging expression remains typechecked in its surrounding type context.

Referenced by: rfc-0078

Dynamic Semantics №1

return, panic, a non-breaking loop, and value-position break or continue diverge and have type !; an enclosing expression cannot produce a value after such a subexpression diverges.

Referenced by: rfc-0078

Tested by (2)
Legality Rule №4

Match exhaustiveness excludes impossible scrutinee values and uninhabited variants.

Referenced by: rfc-0078

Tested by (2)
Legality Rule №5

A match whose scrutinee has type ! is exhaustive with no arms.

Referenced by: rfc-0078

Legality Rule №6

An enum variant containing a ! payload is uninhabited; its match arm may be omitted or, if written, is unreachable but not rejected.

Referenced by: rfc-0078

Tested by (3)
Legality Rule №7

An enum with exactly one inhabited, single-field variant implicitly coerces to that field's type; zero-field or multi-field inhabited variants do not receive this coercion.

Referenced by: rfc-0078

Dynamic Semantics №2

When every arm of a match diverges, the match expression has type !.

Referenced by: rfc-0078

Legality Rule №8

Result<T, !> has an uninhabited Err variant and therefore only an Ok value can be constructed.

Referenced by: rfc-0078

Legality Rule №9

Result<T, !> satisfies the inhabited-singleton coercion rule and a match omitting Err is exhaustive.

Referenced by: rfc-0078

Tested by (2)
Legality Rule №10

Perhaps<!> has only its zero-field None variant inhabited; it does not coerce to a field type.

Referenced by: rfc-0078

Legality Rule №11

A function declared -> ! is legal only when every reachable control-flow path diverges; a reachable ordinary return is a type error.

Referenced by: rfc-0078

Tested by (3)

Perhaps<T>

Perhaps<T> is the built-in optional type. There is no null — all absence is expressed via Perhaps<T>.

The type of None is Perhaps<T> for some T that must be determinable from contextL1. If no context constrains T — for example, a bare let x = None with no annotation and no subsequent use that pins the element type — the program is a type error. An explicit annotation is required in that case:

Changed inv0.11.0RFC-0111None and Some are ordinary variants of Perhaps<T>, not literals

None and Some have no special status in the grammar or the type system. They resolve exactly as Red does for a user-declared enum Colour { Red, .. } — bare where the expected type determines the enum, qualified (Perhaps::None) anywhere. Everything said here about needing a determinable type follows from that general rule rather than from a rule about None specifically, and the same is true of Result<T, E>'s Ok/Err. See §Unqualified variant construct….

fun main() -> i64 {
let x: Perhaps<i64> := None;
match (x) {
Some { value } => value,
None => 0,
}
}
fun main() -> i64 {
let result: Perhaps<i64> := None;
let value: Perhaps<i64> := Some { value = 42 };
match (value) {
Some { value } => value,
None => match (result) {
Some { value } => value,
None => 0,
},
}
}

Use match to unwrap safely:

struct User {
id: i64,
}

fun find_user(id: i64) -> Perhaps<User> {
if (id == 1) {
return Some { value = User { id = 1 } };
}
return None;
}

fun main() -> i64 {
match (find_user(1)) {
Some { value } => value.id,
None => 0,
}
}

.yolo() unwraps, panicking if the value is None:

struct User {
id: i64,
}

fun find_user(id: i64) -> Perhaps<User> {
if (id == 1) {
return Some { value = User { id = 1 } };
}
return None;
}

fun main() -> i64 {
let user := find_user(1).yolo();
return user.id;
}
Formal rules
Legality Rule №1

None is the empty variant of Perhaps<T> and is valid only where the expected type determines T; Perhaps::None is valid wherever the qualified variant is named.

Referenced by: rfc-0020, rfc-0111

Tested by (3)

Result<T, E>

Result<T, E> represents the outcome of a fallible operation:

fun divide(a: f64, b: f64) -> Result<f64, String> {
if (b == 0.0) {
return Err { error = "division by zero" };
}
return Ok { value = a / b };
}

fun main() -> i64 {
match (divide(8.0, 2.0)) {
Ok { value } => value as i64,
Err { error } => 0,
}
}

Use match to handle both cases, or The operator D2 to propagate errors.

.yolo()Panics D1 also works on Result<T, E>, panicking on Err.