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/multiversal-equality.md
+8-7Lines changed: 8 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -27,19 +27,20 @@ But it will probably give unexpected results and fail at runtime.
27
27
Multiversal equality is an opt-in way to make universal equality safer.
28
28
It uses a binary type class [`scala.CanEqual`](https://github.com/lampepfl/dotty/blob/main/library/src/scala/CanEqual.scala)
29
29
to indicate that values of two given types can be compared with each other.
30
-
The example above would not typecheck if there was a given `CanEqual[S, S]` or `CanEqual[T, T]` in scope but would if there was a given `CanEqual[T, S]`. For example:
30
+
The example above would not typecheck if `S` or `T` was a class
31
+
that derives `CanEqual`, e.g.
31
32
32
33
```scala
33
-
givenCanEqual[T, T] =CanEqual.derived
34
+
classTderivesCanEqual
34
35
```
36
+
> Normally a [derives clause](./derivation.md) accepts only type classes with one parameter, however there is a special case for `CanEqual`.
37
+
38
+
Alternatively, one can also provide a `CanEqual` given instance directly, like this:
35
39
36
-
An identical given instance can also be generated through [type class derivation](./derivation.md):
37
40
```scala
38
-
classTderivesCanEqual
41
+
givenCanEqual[T, T] =CanEqual.derived
39
42
```
40
43
41
-
Normally [type class derivation](./derivation.md) accepts only types with one parameter, however there is a special case for `CanEqual`.
42
-
43
44
This definition effectively says that values of type `T` can (only) be
44
45
compared to other values of type `T` when using `==` or `!=`. The definition
45
46
affects type checking but it has no significance for runtime
0 commit comments