Skip to content

Commit 27f6673

Browse files
authored
Blog Post: Announcing Dotty 0.6.0 and 0.7.0-RC1 (#4053)
1 parent 346956e commit 27f6673

File tree

1 file changed

+283
-0
lines changed

1 file changed

+283
-0
lines changed
Lines changed: 283 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,283 @@
1+
---
2+
layout: blog-page
3+
title: Announcing Dotty 0.6.0 and 0.7.0-RC1
4+
author: Allan Renucci
5+
authorImg: /images/allan.jpg
6+
date: 2018-03-05
7+
---
8+
9+
Today, we are excited to release Dotty versions 0.6.0 and 0.7.0-RC1. These releases
10+
serve as a technology preview that demonstrates new language features and the compiler supporting them.
11+
12+
If you’re not familiar with Dotty, it's a platform to try out new language concepts and compiler
13+
technologies for Scala. The focus is mainly on simplification. We remove extraneous syntax
14+
(e.g. no XML literals), and try to boil down Scala’s types into a smaller set of more fundamental
15+
constructs. The theory behind these constructs is researched in
16+
[DOT](https://infoscience.epfl.ch/record/215280), a calculus for dependent object types.
17+
You can learn more about Dotty on our [website](http://dotty.epfl.ch).
18+
19+
<!--more-->
20+
21+
This is our seventh scheduled release according to our [6-week release schedule](http://dotty.epfl.ch/docs/usage/version-numbers.html).
22+
The [previous technology preview](https://github.com/lampepfl/dotty/releases/tag/0.6.0-RC1) focussed
23+
on bug fixes and stability work.
24+
25+
## What’s new in the 0.7.0-RC1 technology preview?
26+
27+
### Enum Simplification [#4003](https://github.com/lampepfl/dotty/pull/4003)
28+
The previously introduced syntax and rules for enum were arguably too complex. We can considerably
29+
simplify them by taking away one capability: that cases can have bodies which can define members.
30+
Arguably, if we choose an ADT decomposition of a problem, it's good style to write all methods using
31+
pattern matching instead of overriding individual cases. So this removes an unnecessary choice.
32+
We now treat enums unequivocally as classes. They can have methods and other statements just like
33+
other classes can. Cases in enums are seen as a form of constructors. We do not need a
34+
distinction between enum class and enum object anymore. Enums can have companion objects just like
35+
normal classes can, of course.
36+
37+
Let's consider how `Option` can be represented as an enum. Previously using an enum class:
38+
```scala
39+
enum class Option[+T] {
40+
def isDefined: Boolean
41+
}
42+
43+
object Option {
44+
case Some[+T](x: T) {
45+
def isDefined = true
46+
}
47+
case None {
48+
def isDefined = false
49+
}
50+
51+
def apply[T](x: T): Option[T] = if (x == null) None else Some(x)
52+
}
53+
```
54+
55+
And now:
56+
```scala
57+
enum Option[+T] {
58+
case Some(x: T)
59+
case None
60+
61+
def isDefined: Boolean = this match {
62+
case None => false
63+
case Some(_) => true
64+
}
65+
}
66+
67+
object Option {
68+
def apply[T](x: T): Option[T] = if (x == null) None else Some(x)
69+
}
70+
```
71+
72+
73+
For more information about [Enumerations](http://dotty.epfl.ch/docs/reference/enums/enums.html)
74+
and how to use them to model [Algebraic Data Types](http://dotty.epfl.ch/docs/reference/enums/adts.html),
75+
visit the respective sections in our documentation.
76+
77+
78+
### Erased terms [#3342](https://github.com/lampepfl/dotty/pull/3342)
79+
The `erased` modifier can be used on parameters, `val` and `def` to enforce that no reference to
80+
those terms is ever used. As they are never used, they can safely be removed during compilation.
81+
82+
One particular use case is to add implicit type constraints that are only relevant at compilation
83+
time. For example, let's consider the following implementation of `flatten`.
84+
85+
```scala
86+
class List[X] {
87+
def flatten[Y](implicit erased ev: X <:< List[Y]): List[Y] = {
88+
val buffer = new mutable.ListBuffer[Y]
89+
this.foreach(e => buffer ++= e.asInstanceOf[List[Y]])
90+
buffer.toList
91+
}
92+
}
93+
94+
List(List(1, 2), List(3)).flatten // List(1, 2, 3)
95+
List(1, 2, 3).flatten // error: Cannot prove that Int <:< List[Y]
96+
```
97+
98+
The implicit evidence `ev` is only used to constrain the type parameter `X` of `List` such that we
99+
can safely cast from `X` to `List[_]`. The usage of the `erased` modifier ensures that the evidence
100+
is not used and can be safely removed at compilation time.
101+
102+
For more information, visit the [Erased Terms](http://dotty.epfl.ch/docs/reference/erased-terms.html)
103+
section of our documentation.
104+
105+
**Note**: Erased terms replace _phantom types_: they have similar semantics, but with the added
106+
advantage that any type can be an erased parameter. See [#3410](https://github.com/lampepfl/dotty/pull/3410).
107+
108+
109+
### Improved IDE support [#3960](https://github.com/lampepfl/dotty/pull/3960)
110+
The Dotty language server now supports context sensitive IDE completions. Completions now include
111+
local and imported definitions. Members completions take possible implicit conversions into account.
112+
113+
<!-- A GIF would be nice? -->
114+
115+
We also improved the `find references` functionality. It is more robust and much faster!
116+
117+
Try it out in [Visual Studio Code](http://dotty.epfl.ch/docs/usage/ide-support.html)!
118+
119+
### Better and safer types in pattern matching (improved GADT support)
120+
121+
Consider the following implementation of an evaluator for a very simple
122+
language containing only integer literals (`Lit`) and pairs (`Pair`):
123+
```scala
124+
sealed trait Exp
125+
case class Lit(value: Int) extends Exp
126+
case class Pair(fst: Exp, snd: Exp) extends Exp
127+
128+
object Evaluator {
129+
def eval(e: Exp): Any = e match {
130+
case Lit(x) =>
131+
x
132+
case Pair(a, b) =>
133+
(eval(a), eval(b))
134+
}
135+
136+
eval(Lit(1)) // 1: Any
137+
eval(Pair(Pair(Lit(1), Lit(2)), Lit(3))) // ((1, 2), 3) : Any
138+
}
139+
```
140+
141+
This code is correct but it's not very type-safe since `eval` returns a value
142+
of type `Any`, we can do better by adding a type parameter to `Exp` that
143+
represents the result type of evaluating the expression:
144+
145+
```scala
146+
sealed trait Exp[T]
147+
case class Lit(value: Int) extends Exp[Int]
148+
case class Pair[A, B](fst: Exp[A], snd: Exp[B]) extends Exp[(A, B)]
149+
150+
object Evaluator {
151+
def eval[T](e: Exp[T]): T = e match {
152+
case Lit(x) =>
153+
// In this case, T = Int
154+
x
155+
case Pair(a, b) =>
156+
// In this case, T = (A, B) where A is the type of a and B is the type of b
157+
(eval(a), eval(b))
158+
}
159+
160+
eval(Lit(1)) // 1: Int
161+
eval(Pair(Pair(Lit(1), Lit(2)), Lit(3))) // ((1, 2), 3) : ((Int, Int), Int)
162+
}
163+
```
164+
165+
Now the expression `Pair(Pair(Lit(1), Lit(2)), Lit(3)))` has type `Exp[((Int,
166+
Int), Int)]` and calling `eval` on it will return a value of type `((Int,
167+
Int), Int)` instead of `Any`.
168+
169+
Something subtle is going on in the definition of `eval` here: its result type
170+
is `T` which is a type parameter that could be instantiated to anything, and
171+
yet in the `Lit` case we are able to return a value of type `Int`, and in the
172+
`Pair` case a value of a tuple type. In each case the typechecker has been able
173+
to constrain the type of `T` through unification (e.g. if `e` matches `Lit(x)`
174+
then `Lit` is a subtype of `Exp[T]`, so `T` must be equal to `Int`). This is
175+
usually referred to as **GADT support** in Scala since it closely mirrors the
176+
behavior of [Generalized Algebraic Data
177+
Types](https://en.wikipedia.org/wiki/Generalized_algebraic_data_type) in
178+
Haskell and other languages.
179+
180+
GADTs have been a part of Scala for a long time, but in Dotty 0.7.0-RC1 we
181+
significantly improved their implementation to catch more issues at
182+
compile-time. For example, writing `(eval(a), eval(a))` instead of `(eval(a),
183+
eval(b))` in the example above should be an error, but it was not caught by
184+
Scala 2 or previous versions of Dotty, whereas we now get a type mismatch error
185+
as expected. More work remains to be done to fix the remaining [GADT-related
186+
issues](https://github.com/lampepfl/dotty/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+gadt),
187+
but so far no show-stopper has been found.
188+
189+
## Trying out Dotty
190+
### Scastie
191+
[Scastie], the online Scala playground, supports Dotty.
192+
This is an easy way to try Dotty without installing anything.
193+
194+
### sbt
195+
Using sbt 0.13.13 or newer, do:
196+
197+
```shell
198+
sbt new lampepfl/dotty.g8
199+
```
200+
201+
This will setup a new sbt project with Dotty as compiler. For more details on
202+
using Dotty with sbt, see the
203+
[example project](https://github.com/lampepfl/dotty-example-project).
204+
205+
### IDE support
206+
It is very easy to start using the Dotty IDE in any Dotty project by following
207+
the [IDE guide](http://dotty.epfl.ch/docs/usage/ide-support.html).
208+
209+
210+
### Standalone installation
211+
Releases are available for download on the _Releases_
212+
section of the Dotty repository:
213+
[https://github.com/lampepfl/dotty/releases](https://github.com/lampepfl/dotty/releases)
214+
215+
We also provide a [homebrew](https://brew.sh/) package that can be installed by running:
216+
217+
```shell
218+
brew install lampepfl/brew/dotty
219+
```
220+
221+
In case you have already installed Dotty via brew, you should instead update it:
222+
223+
```shell
224+
brew upgrade dotty
225+
```
226+
227+
## Let us know what you think!
228+
If you have questions or any sort of feedback, feel free to send us a message on our
229+
[Gitter channel](https://gitter.im/lampepfl/dotty). If you encounter a bug, please
230+
[open an issue on GitHub](https://github.com/lampepfl/dotty/issues/new).
231+
232+
## Contributing
233+
Thank you to all the contributors who made this release possible!
234+
235+
According to `git shortlog -sn --no-merges 0.6.0..0.7.0-RC1` these are:
236+
237+
```
238+
182 Martin Odersky
239+
94 Nicolas Stucki
240+
48 Olivier Blanvillain
241+
38 liu fengyun
242+
16 Allan Renucci
243+
15 Guillaume Martres
244+
11 Aggelos Biboudis
245+
5 Abel Nieto
246+
5 Paolo G. Giarrusso
247+
4 Fengyun Liu
248+
2 Georg Schmid
249+
1 Jonathan Skowera
250+
1 Fedor Shiriaev
251+
1 Alexander Slesarenko
252+
1 benkobalog
253+
1 Jimin Hsieh
254+
```
255+
256+
If you want to get your hands dirty and contribute to Dotty, now is a good time to get involved!
257+
Head to our [Getting Started page for new contributors](http://dotty.epfl.ch/docs/contributing/getting-started.html),
258+
and have a look at some of the [good first issues](https://github.com/lampepfl/dotty/issues?q=is%3Aissue+is%3Aopen+label%3Aexp%3Anovice).
259+
They make perfect entry-points into hacking on the compiler.
260+
261+
We are looking forward to having you join the team of contributors.
262+
263+
## Library authors: Join our community build
264+
Dotty now has a set of widely-used community libraries that are built against every nightly Dotty
265+
snapshot. Currently this includes ScalaPB, algebra, scalatest, scopt and squants.
266+
Join our [community build](https://github.com/lampepfl/dotty-community-build)
267+
to make sure that our regression suite includes your library.
268+
269+
270+
[Scastie]: https://scastie.scala-lang.org/?target=dotty
271+
272+
[@odersky]: https://github.com/odersky
273+
[@DarkDimius]: https://github.com/DarkDimius
274+
[@smarter]: https://github.com/smarter
275+
[@felixmulder]: https://github.com/felixmulder
276+
[@nicolasstucki]: https://github.com/nicolasstucki
277+
[@liufengyun]: https://github.com/liufengyun
278+
[@OlivierBlanvillain]: https://github.com/OlivierBlanvillain
279+
[@biboudis]: https://github.com/biboudis
280+
[@allanrenucci]: https://github.com/allanrenucci
281+
[@Blaisorblade]: https://github.com/Blaisorblade
282+
[@Duhemm]: https://github.com/duhemm
283+

0 commit comments

Comments
 (0)