3. match and exhaustiveness

match dispatches on patterns. The compiler checks exhaustiveness: a missing arm is an error, and the error says which one is missing.

fn sign(x: Int) -> String =
  match x {
    0 -> "zero"
    n if n > 0 -> "positive"
    _ -> "negative"
  }

pub fn main() -> Unit !io = {
  println(sign(0))
  println(sign(7))
  println(sign(-2))
}
Open in playground
zero
positive
negative