Equal 
The Equal
type class describes a type which can be compared for observational equality.
A Equal
must satisfy the following laws:
- Reflexivity:
x === x
for anyx
.
- The indiscernibility of identicals:
- For any
x
andy
, ifx === y
, thenx
andy
are indiscernable
- For any
- The identity of indiscernibles:
- For any
x
andy
, ifx
andy
are indiscernable, thenx === y
- For any
Indiscernability formalizes the intuitive notion of two objects having the exact same properties. Two values x, y: A
are indiscernable if there exists no function f: A => Boolean
such that f(x)
is true
and f(y)
is false
.
These laws entail symmetry and transitivity, which should be easier to test, since they don’t universally quantify over all possible predicates in the language:
- Symmetry:
x === y
if and only ify === x
- Transitivity
- if
x === y
andy === z
, thenx === z
- if
Instance declaration
scala> import scalaz._
import scalaz._
scala> import Scalaz._
import Scalaz._
scala> List(1, 2, 3) === List(1, 2, 3)
res0: Boolean = true