Tin

Examples · learn/06-enums · 118 of 339

positional

Variants can also carry values by position, like a function call.

examples/learn/06-enums/positional.tintin run examples/learn/06-enums/positional.tin
// Variants can also carry values by position, like a function call.
type Command = | Move(int, int) | Say(string) | Quit

fn run(c: Command): string => match c {
  Move(dx, dy) => "move by ({dx}, {dy})"
  Say(text) => "say '{text}'"
  Quit => "bye"
}

fn main() {
  print(run(Move(3, -1)))
  print(run(Say("hello")))
  print(run(Quit))
}