Type System — Mapanare

Static typing with inference. Types where they clarify, inference elsewhere.

Primitive Types

Int (64-bit signed), Float (64-bit IEEE 754), Bool, String (immutable UTF-8), Char (Unicode scalar), Void, Option<T>, Result<T, E>, Tensor<T>[shape], List<T>, Map<K, V>, Signal<T>, Stream<T>, Channel<T>.

Generics

fn identity<T>(x: T) -> T { return x }
struct Pair<A, B> { first: A, second: B }

Trait Bounds

Constrain generic type parameters: fn max<T: Ord>(a: T, b: T) -> T

Option & Result

let x: Option<Int> = Some(42)
fn divide(a: Float, b: Float) -> Result<Float, String> {
    if b == 0.0 { return Err("division by zero") }
    return Ok(a / b)
}
let value = divide(10.0, 3.0)?  // ? operator for error propagation

No OOP

No classes, no inheritance. Structs are product types, enums are sum types (algebraic data types).

Type Aliases

type Name = String
type Matrix = Tensor<Float>[3, 3]
type Callback = fn(Int) -> Bool