Skip to content

Commit 77d4320

Browse files
committed
Kinda roll back changes to multiversal-equality.md
1 parent 48bfbc8 commit 77d4320

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

docs/_docs/reference/contextual/multiversal-equality.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,20 @@ But it will probably give unexpected results and fail at runtime.
2727
Multiversal equality is an opt-in way to make universal equality safer.
2828
It uses a binary type class [`scala.CanEqual`](https://github.com/lampepfl/dotty/blob/main/library/src/scala/CanEqual.scala)
2929
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.
3132

3233
```scala
33-
given CanEqual[T, T] = CanEqual.derived
34+
class T derives CanEqual
3435
```
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:
3539

36-
An identical given instance can also be generated through [type class derivation](./derivation.md):
3740
```scala
38-
class T derives CanEqual
41+
given CanEqual[T, T] = CanEqual.derived
3942
```
4043

41-
Normally [type class derivation](./derivation.md) accepts only types with one parameter, however there is a special case for `CanEqual`.
42-
4344
This definition effectively says that values of type `T` can (only) be
4445
compared to other values of type `T` when using `==` or `!=`. The definition
4546
affects type checking but it has no significance for runtime
@@ -82,7 +83,7 @@ def canEqualAny[L, R]: CanEqual[L, R] = CanEqual.derived
8283
```
8384

8485
Even though `canEqualAny` is not declared as `given`, the compiler will still
85-
construct an `canEqualAny` instance as answer to an implicit search for the
86+
construct a `canEqualAny` instance as answer to an implicit search for the
8687
type `CanEqual[L, R]`, unless `L` or `R` have `CanEqual` instances
8788
defined on them, or the language feature `strictEquality` is enabled.
8889

0 commit comments

Comments
 (0)