Variables & Types

AodhML uses explicit type annotations with inference where unambiguous. Variables are immutable by default; mutability is opt-in.

Variable Declaration

Use let for immutable variables and mut for mutable ones:

let name = "AodhML"      // Immutable, type inferred as String
let count: i32 = 42       // Immutable with explicit type
mut counter = 0           // Mutable, can be reassigned

counter = counter + 1     // OK: counter is mutable
// name = "Other"         // Error: name is immutable

Scalar Types

TypeDescriptionExample
i8, i16, i32, i64Signed integerslet x: i32 = -42
u8, u16, u32, u64Unsigned integerslet x: u32 = 42
f32, f64Floating-pointlet x: f64 = 3.14159
boolBooleanlet ok = true
StringUTF-8 stringlet s = "hello"

Type Inference

The compiler infers types from context when possible:

let inferred = 42           // i32
let precise: f64 = 42.0   // f64 explicitly
let tensor = Tensor::zeros([3, 3])  // Tensor<f32>

Type Aliases

Create named type aliases with the type keyword:

type Vector = Tensor<f32>
type Matrix = Tensor<f32>

fn dot(a: Vector, b: Vector) -> f32 {
    // ...
}

Optionals

Values that may be absent use the Option<T> type:

fn find_index(arr: [i32], target: i32) -> Option<u32> {
    for i, val in arr {
        if val == target {
            return Some(i)
        }
    }
    return None
}