Dotty 0.15.0 and Operators

Mark "Justin" Waks
2 min readMay 24, 2019

--

The latest release of Dotty was announced today; it’s worth taking a look through it. Not many big changes, which is generally good — we’re at the point where things should be starting to settle down a bit.

There’s significant new twist that I haven’t talked about before here: the handling of operators is being regularized a little. In particular, two bits of best practice are getting reified into new annotations. See here for the details, but the quick tl;dr is that:

  • If you define a purely symbolic operator (their example is ++=), you must define an alternate, alphanumeric name for it (in this case, append) using the new @alpha annotation. This will be used as the name for the operator in non-Scala code (eg, using it from Java), and provides documentation on how to pronounce the bloody thing.
  • Today, the use of infix function style is totally ad-hoc, leading to confusion and inconsistency. For Dotty, they are adding a new @infix annotation, which will eventually be required for alphanumeric methods that are to be used in infix position. The notion is that symbolic operators can automatically be used infix (since that is what folks generally expect), but for alphanumeric ones it is up to the function author to declare whether that is appropriate or not. This should cut down on the ad-hockery.

These both seems like small but sensible changes; hopefully they will make it into the final Scala 3 spec…

ETA (May 25): There is currently a robust debate about the @infix annotation happening on the Scala Contributors forum — folks with opinions might want to check that 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”).

Responses (1)