The as
keyword binds a variable to the value matched by a pattern.
It is a more general way of binding variables than using variable patterns alone.
When P
as
x
is matched
against a type T
, the pattern P
is matched against T
, producing typing context Γ.
The typing context produced by the whole match is Γ ∪ {x
has type T
}.
{- Consider this initial program fragment, without an 'as' pattern -} val (a,b) = ((1,2),(3,4)) val (ax,ay) = a val (bx,by) = b {- Compared to the following fragment -} val ((ax,ay) as a, (bx,by) as b) = ((1,2),(3,4)) [ax, ay, a] | [bx, by, b] {- OUTPUT:PERMUTABLE [1, 2, (1, 2)] [3, 4, (3, 4)] -}