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
+11-10Lines changed: 11 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -35,8 +35,9 @@ given [T: Ordering]: Ordering[Option[T]] = Ordering.derived
35
35
It is discouraged to directly refer to the `derived` member if you can use a `derives` clause instead.
36
36
37
37
## Exact mechanism
38
+
In the following, a parameter enumerations where the first index is bigger than the last means there is actually no paramers, for example: `A[T_2, ..., T_1]` means `A`.
39
+
38
40
For a class/trait/object/enum `DerivingType[T_1, ..., T_N] derives TC`, a derived instance is created in `DerivingType`'s companion object (or `DerivingType` itself if it is an object).
39
-
If `DerivingType` does not take parameters, we define `N = 0`.
40
41
41
42
The general "shape" of the derived instance is as follows:
**Note:**`TC.derived` is a normal access, therefore if there are multiple definitions of `TC.derived`, overloading resolution applies.
48
49
49
-
What the derived instance precisely looks like depends on the specifics of `DerivingType` and `TC`, first condition the arity of `TC`:
50
+
What the derived instance precisely looks like depends on the specifics of `DerivingType` and `TC`, the first condition is the arity of `TC`:
50
51
51
52
### `TC` takes 1 parameter
52
53
@@ -59,35 +60,35 @@ The generated instance is then:
59
60
given [T_1:TC, ..., T_N:TC]:TC[DerivingType[T_1, ..., T_N]] =TC.derived
60
61
```
61
62
62
-
If `N == 0`, we understand the above to mean:
63
+
**Note:**If `N == 0`the above means:
63
64
```scala
64
65
givenTC[DerivingType] =TC.derived
65
66
```
67
+
66
68
#### `F` and `DerivingType` have parameters of matching kind on the right
67
69
This section concers cases where you can pair arguments of `F` and `DerivingType` starting from the right such that they have the same kinds pairwise, and all arguments of `F` or `DerivingType` (or both) are used up.
68
-
We also add the requirement that `F` have at least one parameter.
70
+
`F` must also have at least one parameter.
69
71
70
72
The general shape will then be:
71
73
```scala
72
-
given [...]:TC[[...] =>DerivingType[...]] =TC.derived
74
+
given [...]:TC[[...] =>DerivingType[...]] =TC.derived
73
75
```
74
76
Where of course `TC` and `DerivingType` are applied to types of the correct kind.
75
77
76
78
To make this work, we split it into 3 cases:
77
79
78
-
The generated instance is then:
79
80
If `TC` and `DerivingType` take the same number of arguments (`N == K`):
0 commit comments