Possibly replacing `@` with `as`

Mark "Justin" Waks
2 min readSep 19, 2020

--

Things have gotten fairly quiet on the Dotty News front, as the team has in recent months refocused away from new features and towards solidifying the Dotty compiler in time for a Scala 3 launch late this year. (Solidifying the compiler is terribly important, but tends not to produce “news” that the community mostly cares about.)

But here’s an interesting bit of news: Martin has proposed a small syntax change to pattern-matching. Where we currently would see:

x match 
case s @ Success(x, in1) => ...
case f @ Failure(_, in1) => ...

it would instead become:

x match 
case s as Success(x, in1) => ...
case f as Failure(_, in1) => ...

(I’m still getting used to the significant-indentation syntax, and I still don’t like it personally, but I’ll quote the example as he gives it.)

It’s a bit late in the game for a change to Scala 3.0, but this one is plausible, and I think it’s a fine idea. That usage of @ has always been awfully obscure — it’s an arbitrary use of a symbol that isn’t used that way anywhere else, and folks tend to find it hard to remember for a long time when they are learning Scala. By contrast, this one reads exactly correctly: as is the right keyword to mean what it says, and I think most folks would look at this code and immediately understand its intent. It’s a lovely clarification.

The proposal is to allow this as a substitute in Scala 3.0, and then phase out @ starting in 3.1. IMO, that’s a sensible plan, and I hope it works out…

--

--

Mark "Justin" Waks
Mark "Justin" Waks

Written by Mark "Justin" Waks

Lifelong programmer and software architect, specializing in online social tools and (nowadays) Scala. Architect of Querki (“leading the small data revolution”).

No responses yet