Excerpt: From DOT to DOTTY

Scala 3.0
Reading Time: 3 minutes

Hi Guys, In this blog we will see some excerpts from the slides by Martin Odersky and Dmitry Petrashko. How From DOT to DOTTY evolved? So, let’s begin.

The DOT calculus is intended to be a new minimal foundation of Scala which is to be Scala 3. Its type structure is a blueprint for the types used internally in the compiler. DOT is a core calculus for path-dependent types which enhance Scala language and its type systems to next level.

Translated to Scala notation, the language covered by DOT is:

  • Value
    • v = (x: T) => t          Function
    • new { x: T => d }    Object
  • Definition
    • d = def a = t            Method definition
    • type A = T              Type
  • Term
    • t = v                         Value
    • x                              Variable
    • t1(t2)                       Application
    • t.a                            Selection
    • { val x = t1; t2 }     Local definition.

DOT Types The Types covered by DOT are:

  • Type
    • T   =     Any                   Top type
      • Nothing                  Bottom type
      • x.A                           Selection
      • (x: T1) => T2           Function
      • { def a: T }              Method declaration
      • { type T >: T1 <: T2 } Type declaration
      • T1 & T2                    Intersection
      • { x => T }                 Recursion

According to this blog by Martin Odersky:

“What do you get if you boil Scala on a slow flame and wait until all incidental features evaporate and only the most concentrated essence remains? After doing this for 8 years we believe we have the answer: it’s DOT, the calculus of dependent object types, that underlies Scala.”

Therefore, In Scala 3, DOT – Dependent Object Type, has been implemented as foundation of Scala and DOTTY is a project for the development of Scala 3 with DOT. In addition, Scala 3 works on new compiler which is also called Dotty that support DOT and which is more powerful that current version of Scala compiler. Technically, For Scala 2, scalac is compiler, but for Scala 3, dotc is a compiler.

So, the language specification are the same in Scala 2 and Scala 3, but the compiler is new which desugar to DOT. Also, with DOT as foundation, there are additional new features in Scala 3 e.g. union types, intersection-type etc.

What dotty is expected to bring to the table?

Intersection(&) types

(similar to Scala2 with)

trait A {
type T = Int

trait B {
type T = Double

(A with B) # T == Int
(A & B) # T == Int & Double

what is the difference?

  • with is ordered but & is not.
  • A with B is different from B with A but & is not

Union(|) types

(Scala2 equivalent: none)

class A(x: Int)
class B(x: Int)
class C(x: Array[Int])

object Test  {
def foo(x: A | B): Int = x.x
def bar(x: A | C): Int | Array[Int] = x.x

Union(|) types: proper Enumerations

object DaysOfTheWeek {
object Mon
object Tue
object Wed
object Thu
object Fri
object Sat
object Sun

type Weekend = Sat.type | Sun.type
type Workweek = Mon.type | Tue.type | Wed.type | Thu.type | Fri.type
type All = Weekend | Workweek

Trait parameters

trait A(val i: Int)

trait B extends A

class C extends B with A(1)
object O extends A(2) with B

Improved Lazy Val Initialization

object C {
lazy val a0 = {    /* long computation with IO */   }            // <– Thread 1
lazy val a1 = 42              // <– Thread 2 will be waiting for Thread 1 to finish

I hope this gives you an overview of Dotty. For more features look at the blog Scala 3: What’s New? by me and some reference given below.

Till then Stay tuned!! 🙂


Written by 

Charmy is a Software Consultant having experience of more than 1.5 years. She is familiar with Object Oriented Programming Paradigms and has familiarity with Technical languages such as Scala, Lagom, Java, Apache Solr, Apache Spark, Apache Kafka, Apigee. She is always eager to learn new concepts in order to expand her horizon. Her hobbies include playing guitar and Sketching.