You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/docs/reference/contextual/derivation.md
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -40,7 +40,7 @@ The generated typeclass instances are placed in the companion objects `Labelled`
40
40
41
41
A trait or class can appear in a `derives` clause if its companion object defines a method named `derived`. The type and implementation of a `derived` method are arbitrary, but typically it has a definition like this:
42
42
```scala
43
-
defderived[T] withGeneric[T] = ...
43
+
defderived[T] givenGeneric[T] = ...
44
44
```
45
45
That is, the `derived` method takes an inferable parameter of type `Generic` that determines the _shape_ of the deriving type `T` and it computes the typeclass implementation according to that shape. An implied `Generic` instance is generated automatically for any type that derives a typeclass with a `derived`
46
46
method that refers to `Generic`. One can also derive `Generic` alone, which means a `Generic` instance is generated without any other type class instances. E.g.:
@@ -218,7 +218,7 @@ trait Eq[T] {
218
218
We need to implement a method `Eq.derived` that produces an instance of `Eq[T]` provided
219
219
there exists evidence of type `Generic[T]`. Here's a possible solution:
220
220
```scala
221
-
inlinedefderived[T] with (ev: Generic[T]):Eq[T] =newEq[T] {
221
+
inlinedefderived[T] given (ev: Generic[T]):Eq[T] =newEq[T] {
222
222
defeql(x: T, y: T):Boolean= {
223
223
valmx= ev.reflect(x) // (1)
224
224
valmy= ev.reflect(y) // (2)
@@ -315,7 +315,7 @@ calling the `error` method defined in `scala.compiletime`.
315
315
**Example:** Here is a slightly polished and compacted version of the code that's generated by inline expansion for the derived `Eq` instance of class `Tree`.
316
316
317
317
```scala
318
-
implied [T] with (elemEq: Eq[T]) forEq[Tree[T]] {
318
+
implied [T] given (elemEq: Eq[T]) forEq[Tree[T]] {
0 commit comments