Language CoreM2.9
Option<T>, Result<T, E> & Exhaustive match
Null-free optional values, explicit error propagation, and compiler-enforced exhaustive pattern matching.
6 min readUpdated: v0.8.0-rc Reference
Explicit Sum Types Instead of Null
Missing values use `Option<T>` (Some(v) / None) and recoverable failures use `Result<T, E>` (Ok(v) / Err(e)). The compiler rejects any match/eslestir that misses or duplicates a variant.
hadid · EN
fn find_port(name: string): Option<i32> { if (name == "api") { return Option<i32>.Some(8080); } if (name == "web") { return Option<i32>.Some(3000); } return Option<i32>.None;}fn parse_positive(n: i32): Result<i32, string> { if (n <= 0) { return Result<i32, string>.Err("must_be_positive"); } return Result<i32, string>.Ok(n);}match (find_port("api")) { Some(p) => { print("API port: " + json_from_i64(p)); } None => { print("Not configured"); }}match (parse_positive(-5)) { Ok(v) => { print(v); } Err(reason) => { print("Rejected: " + reason); }}