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
**Note**: This page uses the new syntax proposed for implicits that is explored in #5448. This is not yet an endorsement of that syntax, but rather a way to experiment with it.
@@ -47,7 +47,7 @@ A trait or class can appear in a `derives` clause if
47
47
48
48
These two conditions ensure that the synthesized derived instances for the trait are well-formed. The type and implementation of a `derived` method are arbitrary, but typically it has a definition like this:
49
49
```scala
50
-
defderived[T]with (ev: Generic[T]) = ...
50
+
defderived[T](implicitev: Generic[T]) = ...
51
51
```
52
52
That is, the `derived` method takes an implicit parameter of type `Generic` that determines the _shape_ of the deriving type `T` and it computes the typeclass implementation according to that shape. Implicit `Generic` instances are generated automatically for all types that have a `derives` clause. One can also derive `Generic` alone, which means a `Generic` instance is generated without any other type class instances. E.g.:
53
53
```scala
@@ -100,9 +100,15 @@ is represented as `T *: Unit` since there is no direct syntax for such tuples: `
100
100
101
101
### The Generic TypeClass
102
102
103
-
For every class `C[T_1,...,T_n]` with a `derives` clause, the compiler generates in the companion object of `C` a type class instance like this:
103
+
For every class `C[T_1,...,T_n]` with a `derives` clause, the compiler generates in the companion object of `C` an implicit instance of `Generic[C[T_1,...,T_n]]` that follows
@@ -316,7 +324,7 @@ calling the `error` method defined in `scala.compiletime`.
316
324
**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`.
0 commit comments