Skip to main content
Kira

Tuples & Arrays

Tuples

Fixed-size, heterogeneous collections:

let pair: (i32, string) = (42, "hello")
let triple: (i32, bool, f64) = (1, true, 3.14)

// Access by index
let first: i32 = pair.0
let second: string = pair.1

Tuple Destructuring

let pair: (i32, string) = (42, "hello")
let (n, s): (i32, string) = pair

Function Types with Tuples

fn swap[A, B](pair: (A, B)) -> (B, A) {
    let (a, b): (A, B) = pair
    return (b, a)
}

Arrays

Fixed-size, homogeneous collections:

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

The size is part of the type and must be known at compile time.

Function Types

Function types describe callable values:

fn(i32, i32) -> i32              // Function taking two i32, returning i32
fn(string) -> void               // Function taking string, returning nothing
fn() -> bool                     // Function taking nothing, returning bool
fn(fn(i32) -> i32, i32) -> i32   // Higher-order function