Type System
AodhML uses a static, nominative type system with type inference. Types are checked at compile time, eliminating an entire class of runtime errors.
Type Categories
Scalar Types
| Type | Size | Range |
|---|---|---|
i8 | 8 bits | -128 to 127 |
i16 | 16 bits | -32,768 to 32,767 |
i32 | 32 bits | -2^31 to 2^31-1 |
i64 | 64 bits | -2^63 to 2^63-1 |
u8 | 8 bits | 0 to 255 |
u16 | 16 bits | 0 to 65,535 |
u32 | 32 bits | 0 to 2^32-1 |
u64 | 64 bits | 0 to 2^64-1 |
f32 | 32 bits | IEEE 754 single |
f64 | 64 bits | IEEE 754 double |
bool | 1 bit | true, false |
Compound Types
// Array — homogeneous, fixed-size at creation
let arr: [i32] = [1, 2, 3]
// Tuple — heterogeneous, fixed-size
let pair: (i32, String) = (42, "answer")
// Struct — named fields
type Point = struct { x: f64, y: f64 }
// Enum — tagged union
type Result<T, E> = enum {
Ok(T),
Err(E),
}
Generic Types
// Generic struct
type Box<T> = struct {
value: T,
}
// Generic function
fn identity<T>(x: T) -> T {
return x
}
// Trait bounds
fn max<T: Comparable>(a: T, b: T) -> T {
if a > b { return a } else { return b }
}
AI-Native Types
| Type | Description | Status |
|---|---|---|
Tensor<T> | N-dimensional array | Partial |
Dataset<X, Y> | Training data container | Planned |
Model | Neural network model trait | Planned |
Device | Execution device (CPU/GPU) | Planned |
Parameter | Trainable parameter | Planned |
Type Inference
The compiler infers types from context:
let x = 42 // i32 (default integer)
let y = 3.14 // f64 (default float)
let z = [1, 2, 3] // [i32]
let w = true // bool
// Explicit when ambiguous
let a: u64 = 42
let b: f32 = 3.14