Variables & Types

Bindings (let/var), annotations, and the core built-in types.

Variables & Types

Sounio is statically typed, with type inference for most local bindings.

Variable Declaration

Immutable Variables (let)

By default, variables are immutable:

let x = 42          // Type inferred as i32
let name = "Alice"  // Type inferred as string
let pi = 3.14159    // Type inferred as f64

Mutable Variables (var)

Use var for mutable variables:

var counter = 0
counter = counter + 1  // OK

let fixed = 10
fixed = 20  // Error: cannot assign to immutable variable

Type Annotations

You can explicitly annotate types:

let x: i32 = 42
let ratio: f64 = 0.5
let flag: bool = true
let message: string = "Hello"

Primitive Types

TypeDescriptionExample
i8, i16, i32, i64Signed integerslet x: i32 = -42
u8, u16, u32, u64Unsigned integerslet y: u32 = 42
f32, f64Floating pointlet pi: f64 = 3.14
boolBooleanlet flag: bool = true
charUnicode characterlet c: char = 'A'
string / StringText stringlet s = "hello"
strBorrowed string slicelet s: &str = "hello"

Compound Types

Tuples

let point = (10, 20)
let first = point.0  // 10
let second = point.1 // 20

Arrays

let numbers: [i32; 5] = [1, 2, 3, 4, 5]
let first = numbers[0]  // 1

Vectors (Vec<T>)

let items: Vec<i32> = [1, 2, 3, 4]
for x in items {
    // ...
}

Type Inference

Sounio infers types from context:

let values = [1, 2, 3]  // Array literal
let vec_values: Vec<i32> = values

Spec note: units of measure parse (e.g., unit kg; unit g = 0.001 * kg; unit mg = 0.001 * g;) but full unit checking may be gated behind compiler/runtime integration.

Epistemic Types (Knowledge<T>)

For values with uncertainty:

let k = Knowledge { value: 42.0 }
let x: f64 = k.unwrap("accepted for demo")

See Knowledge Types for more details.

What’s Next?