Skip to content

Commit 40a7d10

Browse files
authored
Merge pull request #5977 from Master-Killer/given-syntax
Update to 'given' syntax for inferable parameter
2 parents e777f34 + be121b9 commit 40a7d10

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

docs/docs/reference/contextual/derivation.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ The generated typeclass instances are placed in the companion objects `Labelled`
4040

4141
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:
4242
```scala
43-
def derived[T] with Generic[T] = ...
43+
def derived[T] given Generic[T] = ...
4444
```
4545
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`
4646
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] {
218218
We need to implement a method `Eq.derived` that produces an instance of `Eq[T]` provided
219219
there exists evidence of type `Generic[T]`. Here's a possible solution:
220220
```scala
221-
inline def derived[T] with (ev: Generic[T]): Eq[T] = new Eq[T] {
221+
inline def derived[T] given (ev: Generic[T]): Eq[T] = new Eq[T] {
222222
def eql(x: T, y: T): Boolean = {
223223
val mx = ev.reflect(x) // (1)
224224
val my = ev.reflect(y) // (2)
@@ -315,7 +315,7 @@ calling the `error` method defined in `scala.compiletime`.
315315
**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`.
316316

317317
```scala
318-
implied [T] with (elemEq: Eq[T]) for Eq[Tree[T]] {
318+
implied [T] given (elemEq: Eq[T]) for Eq[Tree[T]] {
319319
def eql(x: Tree[T], y: Tree[T]): Boolean = {
320320
val ev = the[Generic[Tree[T]]]
321321
val mx = ev.reflect(x)

0 commit comments

Comments
 (0)