Skip to content

Commit b8b201d

Browse files
committed
Update reference
1 parent adec842 commit b8b201d

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

docs/docs/reference/multiversal-equality.md

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -56,26 +56,31 @@ each other, but not comparable to anything else:
5656
(As usual, the names of the implicit definitions don't matter, we have
5757
chosen `eqA`, ..., `eqBA` only for illustration).
5858

59-
The `dotty.DottyPredef` object defines a number of `Eq`
60-
implicits. `dotty.DottyPredef` is a temporary `Predef`-like object.
61-
The contents of this object are by default imported into every
62-
program. Once dotty becomes standard Scala, `DottyPredef` will go away
63-
and its contents will be merged with `scala.Predef`.
59+
The `scala.Eq` object defines a number of `Eq` implicits that make
60+
values of types `String`, `Boolean` and `Unit` only comparable to
61+
values of the same type. They also make numbers only comparable to
62+
other numbers, sequences only comparable to other
63+
sequences and sets only comparable to other sets.
6464

65-
The `Eq` instances defined by `DottyPredef` make values of types
66-
`String`, `Boolean` and `Unit` only comparable to values of the same
67-
type. They also make numbers only comparable to other numbers, and
68-
sequences only comparable to other sequences. There's also a
69-
"fallback" instance `eqAny` that allows comparisons over types that do
70-
not themeselves have an `Eq` instance. `eqAny` is defined as follows:
65+
There's also a "fallback" instance named `eqAny` that allows comparisons
66+
over all types that do not themeselves have an `Eq` instance. `eqAny` is
67+
defined as follows:
7168

72-
implicit def eqAny[L, R]: Eq[L, R] = Eq
69+
def eqAny[L, R]: Eq[L, R] = Eq
70+
71+
Even though `eqAny` is not declared implicit, the compiler will still
72+
construct an `eqAny` instance as answer to an implicit search for the
73+
type `Eq[L, R]`, provided that neither `L` nor `R` have `Eq` instances
74+
defined on them.
7375

7476
The primary motivation for having `eqAny` is backwards compatibility,
75-
if this is of no concern one can disable `eqAny` by unimporting it
76-
from `DottyPredef` like this
77+
if this is of no concern one can disable `eqAny` by enabling the language
78+
feature `strictEquality`. As for all language features this can be either
79+
done with an import
80+
81+
import scala.language.strictEquality
7782

78-
import dotty.DottyPredef.{eqAny => _, _}
83+
or with a command line option `-language:strictEquality`.
7984

8085
All `enum` types also come with `Eq` instances that make values of the
8186
`enum` type comparable only to other values of that `enum` type.
@@ -87,11 +92,11 @@ The precise rules for equality checking are as follows.
8792
of the other, or an implicit value of type `scala.Eq[T, U]` is found.
8893

8994
2. The usual rules for implicit search apply also to `Eq` instances,
90-
with one modification: The value `eqAny` in `dotty.DottyPredef` is
91-
eligible only if neither `T` nor `U` have a reflexive `Eq`
95+
with one modification: An instance of `scala.Eq.eqAny[T, U]` is
96+
constructed if neither `T` nor `U` have a reflexive `Eq`
9297
instance themselves. Here, a type `T` has a reflexive `Eq`
93-
instance if the implicit search for `Eq[T, T]` where `eqAny` is
94-
not eligible is successful.
98+
instance if the implicit search for `Eq[T, T]` succeeds
99+
and constructs an instance different from `eqAny`.
95100

96101
More on multiversal equality is found in a [blog post]
97102
and a [Github issue].

0 commit comments

Comments
 (0)