docs / Getting Started / Variables

Variables

Miri has two ways to declare variables:

let — Immutable bindings

let name = "Miri"
let age = 1
let pi = 3.14159
// name = "Other"  // Error: cannot reassign immutable variable

var — Mutable bindings

var counter = 0
counter = counter + 1
counter += 1  // Shorthand works too

Types are inferred but can be explicitly annotated:

let x int = 42
let name string = "Miri"
let flag bool = true

Miri supports a full range of numeric types: i8, i16, i32, i64, i128, u8, u16, u32, u64, u128, f32, f64. The default int is i64 and float is f64.