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
-
## Types supporting `derives` clauses
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.
30
+
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:
32
+
33
+
```scala
34
+
given [T:Ordering]:Ordering[Option[T]] =Ordering.derived
35
+
```
36
+
37
+
It is discouraged to directly refer to the `derived` member if you can use a `derives` clause instead.
30
38
31
39
All data types can have a `derives` clause. This document focuses primarily on data types which also have a given instance
32
40
of the `Mirror` type class available.
33
41
42
+
## `Mirror`
43
+
34
44
`Mirror` type class instances provide information at the type level about the components and labelling of the type.
35
45
They also provide minimal term level infrastructure to allow higher level libraries to provide comprehensive
36
46
derivation support.
@@ -158,15 +168,11 @@ Note the following properties of `Mirror` types,
158
168
+ The methods `ordinal` and `fromProduct` are defined in terms of `MirroredMonoType` which is the type of kind-`*`
159
169
which is obtained from `MirroredType` by wildcarding its type parameters.
160
170
161
-
##Type classes supporting automatic deriving
171
+
### Implementing `derived` with `Mirror`
162
172
163
-
A trait or class can appear in a `derives` clause if its companion object defines a method named `derived`. The
164
-
signature and implementation of a `derived` method for a type class `TC[_]` are arbitrary but it is typically of the
165
-
following form,
173
+
As seen before, the signature and implementation of a `derived` method for a type class `TC[_]` are arbitrary, but we expect it to typically be of the following form:
0 commit comments