Match exhaustively

match tries arms in order and selects the first matching pattern. Used as a value, every arm produces one type.

moon rejects missing cases and unreachable arms. Open types such as integers and strings need a wildcard or binding to close the match; finite enums and optionals can be proven complete case by case.

fn describe(value: int) -> string {
  match value {
    0 => "zero",
    1 | 2 => "small",
    _ => "many",
  }
}

fn main() { println(describe(2)) }
Output & diagnostics
Expected:
small
Ctrl/⌘+Enter runs the current lesson.