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
We say that `Tree` is the _deriving type_ and that the `Eq`, `Ordering` and `Show` instances are _derived instances_.
28
28
29
+
## Exact mechanism
30
+
More formally, for a class/trait/object/enum `DerivingType[T_1, ..., T_N] derives TC` (if `DerivingType` does not take parameters, we define `N = 0`), a derived instance is created in `DerivingType`'s companion object (or `DerivingType` itself if it is an object)
31
+
32
+
What the derived instance looks like depends on the specifics of `DerivingType` and `TC`, first the arity of `TC`:
33
+
34
+
### `TC` takes 1 parameter
35
+
36
+
Therefore `TC` is defined as `TC[F[A_1, ..., A_K]]` (`TC[F]` if `K == 0`), there are two further cases depending on the `A_i`s:
37
+
38
+
#### `F` and all arguments of `DerivingType` have kind `*`
39
+
40
+
The generated instance is then:
41
+
```scala
42
+
given [T_1:TC, ..., T_N:TC]:TC[DerivingType[T_1, ..., T_N]] =TC.derived
43
+
```
44
+
45
+
If `N == 0`, we understand the above to mean:
46
+
```scala
47
+
givenTC[DerivingType] =TC.derived
48
+
```
49
+
50
+
<!-- #### You can pair arguments of `F` and `DerivingType` starting from the right such that they have the same kinds pairwise, and all arguments of at least one of them are used up -->
51
+
#### `F` and `DerivingType` have their `m` rightmost arguments which have the same kind pairwise and `N >= 0`, `K > 0`, and `m == N` and/or `m == K`
More formally, for a class/trait/object/enum `DerivingType derives TC`, the following given instance is created in `DerivingType`'s companion object (or `DerivingType` itself if it is an object):
30
92
* if `DerivingType` doesn't have type parameters
31
93
```scala
@@ -35,6 +97,7 @@ given TC[DerivingType] = TC.derived
0 commit comments