Dotty - in Scala 3

Having listened to Martin Odersky online more recently, I made some notes on his thoughts on Dotty through 2016 and Spring 2017. So, handing over to him, and my quickly made notes:

Dotty features and why

Dotty has the goal to make it simpler – bringing out the essense.

“The Essence of Dependent Object Types” was inspiration.   Ie DOT.  This is DOT Calculus.

Used in Dotty, Note in 2018 we have Scala 2.13, TASTY (typed abstract syntax tree), then 2.14, maybe 2.15 and then Scala 3.0 which is a join of Dotty and Scala

Types, Objects, Functions: Scalastic Principles are to have a synthesis of these 3 things.

Scala does a lot of code generation – ie Implicits are a huge code generator, so they are a form of synthesis.  Implicits are the canonical way to represent contexts – for example environment (prod dev etc).  Cake pattern is an example, or dependency injection, or annotations.

Scalastic Pragmatics: Usability, Power, Simplicity.  Ie new scala devs should find it understandable. 

Look at dotty web site and check the reference section.

Types, Enums, Traits (trait parameters), Implicits.  Ie enums are back!

  • Existential types are gone!    T forSome { type X }
  • Type projections are restricted   T # A     Only remain for inner classes like in Java.

Type changes:

  • Replace compound types.   T with U becomes T & U (intersection types)  and T | U (Union Types)
  • Type lambdas  added:  [X] => T  , ie now primitive

Traits changes

  • How to pass parameters to a trait? Problem was initialisations – you could use abstract values but that’s not great as can get null ptr exceptions.  But you could use early definitions class c extends { val x=E} with T.   ie this was the way to do it, needs to be rewritten as we will have trait T(x: Int).  Was not done before due to inheritance diamonds.  But they now have a rule which says the lowest class to extend the trait must initialise it, and traits cannot pass parameters to super classes.


  • ADTs – using a sealed base trait and children, but no reasonable way to find all the children of the trait.
  • The enum construct supports enumerations and ADTs, maps transparently to classes/objects/etc.
    enum Color{
      case Red,Green, Blue
    enum Color (colorValue:Int){
      case Red extends Color(0xFF0000)
      case Green extends Color(0x00FF00)
      case Blue extends Color(0x0000FF)

Implicits – too much head scratching, too much repetition.   You should use implicit conversions VERY carefully. 

  • In Dotty only implicit METHODS are eligible as conversions.  But ImplicitConverter can be used explicitly to allow abstract over implicit conversions.
  • Disallow type conversions between two packages, in a third package.  Ie you now need to do the conversion within one package.  But this is restricting power and lots of people argue against it.
  • Reduce repetition.  Implicits are the canonical way to represent context.  So rather than pass the parameters, use implicit parameters to avoid tedium, but you end up passing them implicitly up the call stack…that is the repition.
  • So now you can define an implicit type which behind the scenes is more efficient than implicit closures – called Implicit Function Types