Skip to content

Commit 1b7f0f1

Browse files
committed
Address Martin’s review
1 parent c6af77e commit 1b7f0f1

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

blog/_posts/2020-05-05-scala-3-import-suggestions.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ a complete type hierarchy.
1111

1212
However, working with implicits can be a difficult experience. Thankfully, the
1313
Scala 3 compiler dramatically
14-
improves the quality of the error messages shown in case of missing implicit so
14+
improves the quality of the error messages shown in case of missing implicits so
1515
that it is easier to see _where_ an implicit argument could not be inferred
1616
by the compiler, and _how_ to fix the problem.
1717

@@ -214,13 +214,14 @@ trait Traverse[F[_]] {
214214
trait Applicative[F[_]]
215215
~~~
216216

217-
Let’s assume that an implicit instance of type `Traverse[List]` and an implicit instance
218-
of type `Applicative[Option]` are defined in an object `Implicits`:
217+
Let’s assume that a given instance of type `Traverse[List]` and a given instance
218+
of type `Applicative[Option]` are defined in an object `Givens` (given instances
219+
are the new way to define implicit instances in Scala 3):
219220

220221
~~~
221-
object Implicits {
222-
implicit def traverseList: Traverse[List] = ???
223-
implicit def applicativeOption: Applicative[Option] = ???
222+
object Givens {
223+
given traverseList as Traverse[List] = ???
224+
given applicativeOption as Applicative[Option] = ???
224225
}
225226
~~~
226227

@@ -274,10 +275,10 @@ Compiling with Scala 3, on the other hand, provides much better assistance:
274275
|
275276
|The following import might make progress towards fixing the problem:
276277
|
277-
| import Implicits.traverseList
278+
| import Givens.traverseList
278279
~~~
279280

280-
Let’s apply the suggestion and import `Implicits.traverseList`. Now, the compiler
281+
Let’s apply the suggestion and import `Givens.traverseList`. Now, the compiler
281282
provides the following error:
282283

283284
~~~
@@ -288,15 +289,15 @@ Error:
288289
|
289290
|The following import might fix the problem:
290291
|
291-
| import Implicits.applicativeOption
292+
| import Givens.applicativeOption
292293
~~~
293294

294-
If we apply the new suggestion (importing `Implicits.applicativeOption`) our
295+
If we apply the new suggestion (importing `Givens.applicativeOption`) our
295296
program compiles!
296297

297-
The Scala 3 compiler first suggested importing `Implicits.traverseList`, so
298+
The Scala 3 compiler first suggested importing `Givens.traverseList`, so
298299
that the extension method `traverse` becomes available. Then, it suggested
299-
importing `Implicits.applicativeOption`, which was required to call the `traverse`
300+
importing `Givens.applicativeOption`, which was required to call the `traverse`
300301
operation.
301302

302303
## Summary

0 commit comments

Comments
 (0)