Skip to content

Commit d4d0a21

Browse files
Merge pull request #7269 from dotty-staging/blog-rc-19
0.19.0-RC1 Blog Article
2 parents 4337431 + f8fb3dd commit d4d0a21

File tree

2 files changed

+237
-1
lines changed

2 files changed

+237
-1
lines changed

docs/blog/_posts/2019-08-30-18th-dotty-milestone-release.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ If you have questions or any sort of feedback, feel free to send us a message on
284284

285285
Thank you to all the contributors who made this release possible!
286286

287-
According to `git shortlog -sn --no-merges 0.17.0-RC1..0.18.0-RC1` these are:
287+
According to `git shortlog -sn --no-merges 0.17.0-RC1..0.18.1-RC1` these are:
288288

289289
```
290290
106 Nicolas Stucki
Lines changed: 236 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,236 @@
1+
---
2+
layout: blog-page
3+
title: Announcing Dotty 0.19.0-RC1 – further refinements of the syntax and the migration to 2.13.1 standard library
4+
author: Anatolii Kmetiuk
5+
authorImg: /images/anatolii.png
6+
date: 2019-09-23
7+
---
8+
9+
Greetings! With this post, we are proud to announce the 19th release of Dotty. This release features further changes to the syntax following the feedback from the community and further discussion. Another important change is the migration to the 2.13.1 standard library.
10+
11+
This release serves as a technology preview that demonstrates new
12+
language features and the compiler supporting them.
13+
14+
Dotty is the project name for technologies that are being considered for
15+
inclusion in Scala 3. Scala has pioneered the fusion of object-oriented and
16+
functional programming in a typed setting. Scala 3 will be a big step towards
17+
realising the full potential of these ideas. Its main objectives are to
18+
19+
- become more opinionated by promoting programming idioms we found to work well,
20+
- simplify where possible,
21+
- eliminate inconsistencies and surprising behaviours,
22+
- build on strong foundations to ensure the design hangs together well,
23+
- consolidate language constructs to improve the language’s consistency, safety, ergonomics, and
24+
performance.
25+
26+
You can learn more about Dotty on our [website](https://dotty.epfl.ch).
27+
28+
<!--more-->
29+
30+
# What’s new in the 0.19.0-RC1 technology preview?
31+
## Given syntax reworked
32+
`the` method (a better version of `implicitly` in Scala 3) was renamed to `summon`.
33+
34+
`given` definitions now closely resemble ordinary definitions:
35+
36+
```scala
37+
given Int = 10 // Anonymous
38+
given x: String = "foo" // Named
39+
given f(given x: Int): Option[Int] = Some(x * x) // With given parameters
40+
given [T](given opt: Option[T]): List[T] = opt.toList // Anonymous with type parameters
41+
42+
@main def Test = println(summon[List[Int]])
43+
```
44+
45+
Note that `as` was dropped and `given` must now go inside the parentheses as opposed of being used in an infix style.
46+
47+
All of the experimental syntax related to givens – such as `delegate for`, `given as`, infix-style `given` – is now dropped.
48+
49+
## Colons dropped from class or object definitions
50+
Now you can define an object as follows:
51+
52+
```scala
53+
object Bar
54+
val x = 10
55+
56+
@main def Test = println(Bar.x) // 10
57+
```
58+
59+
In `0.18.1-RC1`, you would have needed to put a colon after `Bar`. The colon was also dropped for traits, classes and enums.
60+
61+
## Allow `given` in pattern bindings
62+
Consider you have the following monadic flow:
63+
64+
```scala
65+
for
66+
x <- bar
67+
res <- foo(given x)
68+
yield res
69+
```
70+
71+
Writing entire programs in a monadic flow is not uncommon in functional programming. When working in this style, a situation may arise as shown above: one statement of the monadic flow implicitly depends on the result of another one. It was impossible to declare a pattern variable as a given, which necessitated passing it around explicitly. Not anymore! Now, you can write the above code as follows:
72+
73+
```scala
74+
for
75+
given x: Int <- bar // Int, or whatever type you are extracting
76+
res <- foo
77+
yield res
78+
```
79+
80+
Note that the type of the given variable must be specified explicitly.
81+
82+
Full example:
83+
84+
```scala
85+
def foo(given x: Int): Option[Int] = Some(x * x)
86+
def bar = Some(10)
87+
88+
@main def Test =
89+
for
90+
given x: Int <- bar
91+
res <- foo
92+
yield println(res)
93+
```
94+
95+
This syntax is allowed anywhere where a pattern is allowed. So you can write:
96+
97+
```scala
98+
user match
99+
case User(_, Some(given email: Email)) => sendEmail
100+
```
101+
102+
Full example:
103+
104+
```scala
105+
opaque type Email = String
106+
object Email
107+
def apply(value: String): Email = value
108+
109+
def sendEmail(given m: Email): Unit =
110+
println(s"Sent an email to $m")
111+
112+
case class User(name: String, email: Option[Email])
113+
114+
@main def Test =
115+
val user = User("Tom", Some(Email("[email protected]")))
116+
user match
117+
case User(_, Some(given email: Email)) => sendEmail
118+
```
119+
120+
## Replace given matches by a library method
121+
Given matches was a feature that allowed to query the implicit scope and execute different logic based on what was found there. We have replaced this feature with a library method called `summonFrom`. You can use it as follows:
122+
123+
```scala
124+
import compiletime.summonFrom
125+
126+
given Int = 10
127+
128+
@main inline def Test = summonFrom {
129+
case str: String => println(s"String $str")
130+
case int: Int => println(s"Int $int") // Int 10
131+
}
132+
```
133+
134+
The above code will print "Int 10" since an integer with the value 10 was present in the implicit scope but no String was present.
135+
136+
Notice that we had to define the `Test` method as `inline` since `summonFrom` can only be used from an inline method.
137+
138+
## Wildcard types written with `?`
139+
You can now use both `_` and `?` to express wildcard types. For example:
140+
141+
```scala
142+
@main def Test =
143+
val xs: List[Int] = (1 to 10).toList
144+
xs match
145+
case xss: List[?] => println(s"It is a list")
146+
```
147+
148+
This is the first step in a multi-step process to disallow `_` as wildcards so that we can use underscores for both terms and type parameters instead. This will make the language more regular.
149+
150+
## Lambda parameters must be enclosed in parentheses
151+
Lambda parameters with type ascriptions are now required to be enclosed in parentheses. E.g. `x: Int => x * x` is no longer legal, it must be written as `(x: Int) => x * x`. However, you can still write `x => x * x`, that is, if `x` does not have an explicit type ascription.
152+
153+
## Dottydoc redesign
154+
The output of [Dottydoc](https://dotty.epfl.ch/docs/usage/dottydoc.html) has been redesigned. It is now fully responsive: every element, including API docs and search, is adapted to both small and big screens.
155+
156+
The most visible changes are the toolbar and the sidebar. They now have a common darker background, which makes them more readable and helps separating navigation from content. Also, the sidebar is collapsible and has been optimized so that it doesn't glitch when the page loads.
157+
158+
The toolbar's logo can now be set with the `-project-logo` option.
159+
For instance, `-project-logo dotty-logo.svg` will make `/images/dotty-logo.svg` appear in the toolbar.
160+
161+
[The front page](https://dotty.epfl.ch) has been redesigned too, with a new responsive menu and improved contrast.
162+
163+
Overall, every page has been updated with consistent settings of fonts and colors. A more detailed comparison between the new and the old design can be found [here](https://github.com/lampepfl/dotty/pull/7153).
164+
165+
## Metaprogramming Progress
166+
We're making steady progress on the Dotty metaprogramming capability. In our previous work, we've implemented a bunch of functions for working with expressions. For example, we have a capability to convert a list of expressions into an expression of list, or a tuple of expressions into an expression of tuple.
167+
168+
In this release, we have collected this family of functions in one place – the companion object `scala.quoted.Expr`. Currently, the following methods are available in that object for working with expressions:
169+
170+
- nullExpr – an expression of `null`.
171+
- unitExpr – an expression of `unit`.
172+
- block – given a list of statements and a final expression, concatenates them in a block.
173+
- ofSeq, ofList – constructs an expression of collection from a collection of expressions
174+
- ofTuple – constructs an expression of tuple from either a tuple of expressions or a sequence of expressions.
175+
176+
Also, `x.toExpr` syntax which lifts `x` into an expression is now deprecated. It is replaced with `Expr(x)`.
177+
178+
# Let us know what you think!
179+
180+
If you have questions or any sort of feedback, feel free to send us a message on our
181+
[Gitter channel](https://gitter.im/lampepfl/dotty). If you encounter a bug, please
182+
[open an issue on GitHub](https://github.com/lampepfl/dotty/issues/new).
183+
184+
## Contributing
185+
186+
Thank you to all the contributors who made this release possible!
187+
188+
According to `git shortlog -sn --no-merges 0.18.1-RC1..0.19.0-RC1` these are:
189+
190+
```
191+
87 Martin Odersky
192+
50 Nicolas Stucki
193+
42 Guillaume R
194+
33 Nikita Eshkeev
195+
20 Guillaume Martres
196+
9 Liu Fengyun
197+
8 Anatolii
198+
5 Robert Stoll
199+
3 Miles Sabin
200+
1 Sam Desborough
201+
1 Anatolii Kmetiuk
202+
1 Jon Pretty
203+
1 Oron Port
204+
1 Aggelos Biboudis
205+
```
206+
207+
If you want to get your hands dirty and contribute to Dotty, now is a good time to get involved!
208+
Head to our [Getting Started page for new contributors](https://dotty.epfl.ch/docs/contributing/getting-started.html),
209+
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).
210+
They make perfect entry points into hacking on the compiler.
211+
212+
We are looking forward to having you join the team of contributors.
213+
214+
## Library authors: Join our community build
215+
216+
Dotty now has a set of widely-used community libraries that are built against every nightly Dotty
217+
snapshot. Currently, this includes ScalaPB, algebra, scalatest, scopt and squants.
218+
Join our [community build](https://github.com/lampepfl/dotty-community-build)
219+
to make sure that our regression suite includes your library.
220+
221+
[Scastie]: https://scastie.scala-lang.org/?target=dotty
222+
223+
[@odersky]: https://github.com/odersky
224+
[@DarkDimius]: https://github.com/DarkDimius
225+
[@smarter]: https://github.com/smarter
226+
[@felixmulder]: https://github.com/felixmulder
227+
[@nicolasstucki]: https://github.com/nicolasstucki
228+
[@liufengyun]: https://github.com/liufengyun
229+
[@OlivierBlanvillain]: https://github.com/OlivierBlanvillain
230+
[@biboudis]: https://github.com/biboudis
231+
[@allanrenucci]: https://github.com/allanrenucci
232+
[@Blaisorblade]: https://github.com/Blaisorblade
233+
[@Duhemm]: https://github.com/Duhemm
234+
[@AleksanderBG]: https://github.com/AleksanderBG
235+
[@milessabin]: https://github.com/milessabin
236+
[@anatoliykmetyuk]: https://github.com/anatoliykmetyuk

0 commit comments

Comments
 (0)