Features Introduced In Dotty

Table of contents
Reading Time: 2 minutes

DOTTY is a faster compiler that comes with Scala 3.
There are many new features introduced in DOTTY that are discussed further in this blog, but before reading this blog please go through the blog introduction on Dotty, to get a basic idea about dotty.

Multiversal Equality
Scala’s == and != are used to compare values of any type. This is known as universal equality that Scala uses. It is convenient to use but doesn’t guarantee type safety. Suppose there is a program in which a variable y has type T but it expects type S.

Trait Parameters
Scala 2 compiler doesn’t let the trait to have parameters. But Dotty allows the same. An example demonstrating the trait parameters is shown below:

But we need to use the parameterized trait carefully. Consider the following cases:
Suppose a trait is extended twice as shown, then it will result in an error.

Suppose a trait extends parameterized trait Greeting and there is a class E that extends the trait FormalGreeting, then we encounter an error.

To avoid the error, needs to extend both FormalGreeting and Greeting as shown:

In the previous blog of introduction to dotty, It was mentioned that Macros are a dropped feature of DottyInline modifier helps to achieve the aim of macros.

In this the inline val has a constant value. When used in this way, the inline val behaves similar to the final variables of Scala.

Automatic Tupling of Function Parameters
Lets take an example of list,

To convert this list of tuples of Integers to list of Integers so that each pair of numbers is mapped to their sum. Previously, the best way to do this was with a pattern-matching decomposition

Now, dotty provides us to write this in this way


Isn’t this more convenient, So basically a function value with more than one parameters can be converted to a function with tupled arguments if the expected type is a unary function type of the form ((T_1, …, T_n)) => U

So these were just some of the features that are provided to us by Dotty, there are many more yet to discuss and will be done in our next blog for the same.