As-patterns

An as-pattern has the form v@p where v is a regular identifier and p is a pattern. This pattern matches if p matches, and the variable v will be bound in the body to the value matching p.

For example, this expression evaluates to 3:

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