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:
| Category | Examples | Chapter |
|---|---|---|
| Primitives | bool, u64, U256, address | Primitive Types |
| Generics | Vec<T>, HashMap<K,V>, Option<T> | Generic Types |
| Records | record Pool { ... } | Records |
| Enums | enum Status { Active, Paused } | Enums |
| Type Aliases | type Amount = U256 | Type 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.