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
-
**Note:** The access to `derived` above is a normal access, therefore if there are multiple definitions of `derived` in the type class, overloading resolution applies.
29
+
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
+
* if `DerivingType` doesn't have type parameters
31
+
```scala
32
+
givenTC[DerivingType] =TC.derived
33
+
```
34
+
* if `DerivingType` has type parameters `[T_1, ..., T_N]`
35
+
```scala
36
+
given [T_1:TC, ... T_N:TC]:TC[DerivingType[T_1, ..., T_N]] =TC.derived
37
+
```
38
+
39
+
`TC.derived` should be an expression that conforms to the expected type `TC[DerivingType]`, potentially elaborated using term and/or type inference.
40
+
41
+
**Note:**`TC.derived` is a normal access, therefore if there are multiple definitions of `TC.derived`, overloading resolution applies.
30
42
31
-
**Note:**`derived` can be used manually, this is useful when you do not have control over the definition. For example we can implement an`Ordering` for `Option`s like so:
43
+
**Note:**`TC.derived` can be used manually, this is useful when you do not have control over the definition. For example we can implement `Ordering` for `Option`s like so:
32
44
33
45
```scala
34
46
given [T:Ordering]:Ordering[Option[T]] =Ordering.derived
35
47
```
36
48
37
49
It is discouraged to directly refer to the `derived` member if you can use a `derives` clause instead.
38
50
51
+
#### CanEqual
52
+
53
+
With `DerivingType[T_1, ..., T_N] derives CanEqual`, the following instance is created:
0 commit comments