dotty

Notes on using Dotty (Scala 3), SBT, and VS Code together

As a note to self, here are some ways to work with Dotty (Scala 3), SBT, and VS Code (Visual Studio Code).

Create a Dotty project:

sbt new lampepfl/dotty.g8

Launch VS Code inside that project directory, with Dotty support:

sbt launchIDE

Start SBT as usual:

sbt

Those notes are just a reminder for myself, but hopefully they’ll also help others work with Dotty, SBT, and VS Code.

Dotty (Scala 3) v20 for/do loop syntax

Just fooling around a little bit at the moment, here are several ways to write for/do blocks with the “significant indentation” style in Dotty (Scala 3) as of Dotty v20:

Examples of converting Scala 2 code to Scala 3 with Dotty 0.20

Table of Contents1 - Significant indentation syntax with traits and classes2 - match expressions3 - for loops and if/else (and `do` and `then`)4 - try/catch syntax5 - A couple of braces not removed6 - More Dotty/Scala 3 changes

With the Dotty compiler you can convert Scala 2 code to the new Scala 3 syntax, and with the Dotty 0.20.0-RC1 release on November 4, 2019, I thought I’d see how some of the conversions work. Almost all of the changes shown below have to do with the elimination of curly braces and the use of “significant indentation” syntax, but in one example I also show the then and do keywords.

An example of using enums in Scala 3 (Dotty)

Here’s a quick example of how to use Scala 3 (Dotty) enums, including using them as constructor and method parameters, and in a match expression. First, some Scala 3 enums for a pizza store application: