Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Types

Cambrian is a statically typed language. Every variable, parameter, member, and expression has a type that is known at compile time. The type system emphasises explicit widths, checked vs wrapping arithmetic, and clear address / collection types so state transitions stay predictable across backends.

Type Categories

Cambrian types fall into several categories:

CategoryExamplesChapter
Primitivesbool, u64, U256, addressPrimitive Types
GenericsVec<T>, HashMap<K,V>, Option<T>Generic Types
Recordsrecord Pool { ... }Records
Enumsenum Status { Active, Paused }Enums
Type Aliasestype Amount = U256Type Aliases
Tuples(u64, address), (bool, U256, u8)See below

Tuples

Cambrian supports tuple types for grouping a fixed number of values:

pure fn split(total: u64) -> (u64, u64) {
    let half = total / 2;
    (half, total - half)
}

Tuples are positional – their elements are accessed by index or via destructuring in let bindings:

let pair: (u64, bool) = (42, true);

Tuples are most useful as return types for pure functions and as intermediate values in expressions.

Type Annotations

Type annotations appear after a colon in variable bindings, function parameters, member declarations, and return types:

let count: u64 = 0;

pure fn add(a: u64, b: u64) -> u64 {
    a + b
}

In many positions, such as let bindings in blocks, the type can be inferred by the compiler.

Type Casts

The as keyword performs explicit type conversion between compatible types:

let small: u8 = 255;
let big: u64 = small as u64;

Type casting is especially common when working with mixed-width integer arithmetic. See Arithmetic and Logic for details on checked and wrapping operations across types.