As-patterns

Anas-patternhas the formv@pwherevis aregular identifierandpis a pattern. This pattern matches ifpmatches, and the variablevwill be bound in the body to the value matchingp.

For example, this expression evaluates to3:

matchExpression : Nat
matchExpression =
  use Nat +
  match 1 + 1 with
    x@4 ->
      use Nat *
      x * 2
    y@2 -> y + 1
    _   -> 22