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 read by destructuring in let
bindings:
let (lo, hi) = split(total);
Tuples are supported only as multi-value return types and in let
destructuring. They cannot be used as member types or collection elements
(Vec<(u64, address)>); define a record instead.
Type Annotations
Type annotations appear after a colon in function parameters, route parameters, member declarations, and return types:
pure fn add(a: u64, b: u64) -> u64 {
a + b
}
let bindings in routes and blocks do not take a type annotation; their type
is inferred from the right-hand side. Use a cast or a typed parameter when
you need a specific width.
Type Casts
The as keyword performs explicit type conversion between compatible types:
let big = 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.