Description
I have a late syntax change proposal: Change @
as the pattern matching binder to as
.
Example:
x match
case s as Success(x, in1) => ...
case f as Failure(_, in1) => ...
e match
case (xs as hd :: tl, y) => ...
Why @
is not a good choice for pattern matching:
-
It is an obscure symbol with a different meaning. I find the two worst operators to use in programming languages are
@
and$
since both have everyday uses that have nothing to do with their role in programming. We have avoided$
so far, let's get rid of@
as well. -
It comes with the wrong precedence.
@
binds more weakly than every other infix operator, yet being a non-standard symbol it would suggest that it binds more strongly.
By contrast, as
is readable and it comes with the right precedence. It also reinforces learning in relation to givens. In both cases x as
would be an optional label.
An objection could be that in patterns, as
would be followed by a pattern whereas in givens it's followed by a type. But there's precedence for that: |
plays a similar dual role: it connects patterns in patterns and types in types.
Migration
For 3.0, allow both as
and @
. For 3.1. either deprecate @
or disallow it altogether and offer an automatic rewrite.