Skip to content

Update to 'given' syntax for inferable parameter #5977

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 23, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/docs/reference/contextual/derivation.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ The generated typeclass instances are placed in the companion objects `Labelled`

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:
```scala
def derived[T] with Generic[T] = ...
def derived[T] given Generic[T] = ...
```
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`
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.:
Expand Down Expand Up @@ -218,7 +218,7 @@ trait Eq[T] {
We need to implement a method `Eq.derived` that produces an instance of `Eq[T]` provided
there exists evidence of type `Generic[T]`. Here's a possible solution:
```scala
inline def derived[T] with (ev: Generic[T]): Eq[T] = new Eq[T] {
inline def derived[T] given (ev: Generic[T]): Eq[T] = new Eq[T] {
def eql(x: T, y: T): Boolean = {
val mx = ev.reflect(x) // (1)
val my = ev.reflect(y) // (2)
Expand Down Expand Up @@ -315,7 +315,7 @@ calling the `error` method defined in `scala.compiletime`.
**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`.

```scala
implied [T] with (elemEq: Eq[T]) for Eq[Tree[T]] {
implied [T] given (elemEq: Eq[T]) for Eq[Tree[T]] {
def eql(x: Tree[T], y: Tree[T]): Boolean = {
val ev = the[Generic[Tree[T]]]
val mx = ev.reflect(x)
Expand Down