@@ -11,7 +11,7 @@ a complete type hierarchy.
11
11
12
12
However, working with implicits can be a difficult experience. Thankfully, the
13
13
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
15
15
that it is easier to see _ where_ an implicit argument could not be inferred
16
16
by the compiler, and _ how_ to fix the problem.
17
17
@@ -214,13 +214,14 @@ trait Traverse[F[_]] {
214
214
trait Applicative[F[_]]
215
215
~~~
216
216
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):
219
220
220
221
~~~
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] = ???
224
225
}
225
226
~~~
226
227
@@ -274,10 +275,10 @@ Compiling with Scala 3, on the other hand, provides much better assistance:
274
275
|
275
276
|The following import might make progress towards fixing the problem:
276
277
|
277
- | import Implicits .traverseList
278
+ | import Givens .traverseList
278
279
~~~
279
280
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
281
282
provides the following error:
282
283
283
284
~~~
@@ -288,15 +289,15 @@ Error:
288
289
|
289
290
|The following import might fix the problem:
290
291
|
291
- | import Implicits .applicativeOption
292
+ | import Givens .applicativeOption
292
293
~~~
293
294
294
- If we apply the new suggestion (importing ` Implicits .applicativeOption` ) our
295
+ If we apply the new suggestion (importing ` Givens .applicativeOption` ) our
295
296
program compiles!
296
297
297
- The Scala 3 compiler first suggested importing ` Implicits .traverseList` , so
298
+ The Scala 3 compiler first suggested importing ` Givens .traverseList` , so
298
299
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 `
300
301
operation.
301
302
302
303
## Summary
0 commit comments