Skip to content

Commit 9cfffac

Browse files
committed
Small aestethic fixes
1 parent f93026b commit 9cfffac

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

docs/_docs/reference/contextual/derivation.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ given [T: Ordering]: Ordering[Option[T]] = Ordering.derived
3535
It is discouraged to directly refer to the `derived` member if you can use a `derives` clause instead.
3636

3737
## 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+
3840
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`.
4041

4142
The general "shape" of the derived instance is as follows:
4243
```scala
@@ -46,7 +47,7 @@ given [...]: TC[ ... DerivingType[...] ... ] = TC.derived
4647

4748
**Note:** `TC.derived` is a normal access, therefore if there are multiple definitions of `TC.derived`, overloading resolution applies.
4849

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`:
5051

5152
### `TC` takes 1 parameter
5253

@@ -59,35 +60,35 @@ The generated instance is then:
5960
given [T_1: TC, ..., T_N: TC]: TC[DerivingType[T_1, ..., T_N]] = TC.derived
6061
```
6162

62-
If `N == 0`, we understand the above to mean:
63+
**Note:** If `N == 0` the above means:
6364
```scala
6465
given TC[DerivingType] = TC.derived
6566
```
67+
6668
#### `F` and `DerivingType` have parameters of matching kind on the right
6769
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.
6971

7072
The general shape will then be:
7173
```scala
72-
given [...]: TC[[...] => DerivingType[...]] = TC.derived
74+
given [...]: TC[ [...] => DerivingType[...] ] = TC.derived
7375
```
7476
Where of course `TC` and `DerivingType` are applied to types of the correct kind.
7577

7678
To make this work, we split it into 3 cases:
7779

78-
The generated instance is then:
7980
If `TC` and `DerivingType` take the same number of arguments (`N == K`):
8081
```scala
8182
given TC[DerivingType] = TC.derived
8283
// simplified form of:
83-
// given TC[[A_1, ..., A_K] => DerivingType[A_1, ..., A_K]] = TC.derived
84+
given TC[ [A_1, ..., A_K] => DerivingType[A_1, ..., A_K] ] = TC.derived
8485
```
8586
If `DerivingType` takes less arguments than `TC` (`N < K`), we throw away the leftmost ones:
8687
```scala
87-
given TC[[A_1, ..., A_K] =>> DerivingType[A_(K-N+1), ..., A_K]] = TC.derived
88+
given TC[ [A_1, ..., A_K] =>> DerivingType[A_(K-N+1), ..., A_K] ] = TC.derived
8889

8990
// if DerivingType takes no arguments (N == 0), the above simplifies to:
90-
given TC[[A_1, ..., A_K] =>> DerivingType] = TC.derived
91+
given TC[ [A_1, ..., A_K] =>> DerivingType ] = TC.derived
9192
```
9293

9394
If `TC` takes less arguments than `DerivingType` (`K < N`), we fill in the leftmost slots with type parameters:
@@ -107,7 +108,7 @@ Let `U_1`, ..., `U_M` be the parameters of `DerivingType` of kind `*`.
107108
The generated instance is then:
108109
```scala
109110
given [T_1L, T_1R, ..., T_NL, T_NR] // every parameter of DerivingType twice
110-
(using CanEqual[U_1L, U_1R], ..., CanEqual[U_NL, U_NR]): // only parameters of Deriving type with kind *
111+
(using CanEqual[U_1L, U_1R], ..., CanEqual[U_ML, U_MR]): // only parameters of DerivingType with kind *
111112
CanEqual[DerivingType[T_1L, ..., T_NL], DerivingType[T_1R, ..., T_NR]] = // again, every parameter
112113
CanEqual.derived
113114
```

0 commit comments

Comments
 (0)