Code for manipulation equivalence classes on index types. An
is an equivalence relation. The empty equivalence relation is constructed
over a ranges of values using
emptyEquivalence. Less discerning
equivalence relations can be obtained with
The relation can be tested with
equivalent, and canonical
representatives can be chosen with
An example follows:
import Data.Equivalence.Persistent rel = equateAll [1,3,5,7,9] . equate 5 6 . equate 2 4 $ emptyEquivalence (1,10) test1 = equiv rel 3 5 -- This is True test2 = equiv rel 1 6 -- This is True test3 = equiv rel 4 6 -- This is False
- data Equivalence i
- emptyEquivalence :: Ix i => (i, i) -> Equivalence i
- repr :: Ix i => Equivalence i -> i -> i
- equiv :: Ix i => Equivalence i -> i -> i -> Bool
- equivalent :: Ix i => Equivalence i -> [i] -> Bool
- equate :: Ix i => i -> i -> Equivalence i -> Equivalence i
- equateAll :: Ix i => [i] -> Equivalence i -> Equivalence i
Equivalence is an equivalence relation on a range of values of some
emptyEquivalence is an equivalence relation that equates two values
only when they are equal to each other. It is the most discerning such
repr gives a canonical representative of the equivalence class
x. It is chosen arbitrarily, but is always the same for a
given equivalence relation.
This function is slightly unsafe. In particular, it's possible to build
the same equivalence relation by equating values in two different orders,
and the choice of canonical representatives will differ. You can either
think of a value of type
Equivalence as an equivalence relation together
with a choice of canonical representatives, or you can consider this not a
pure function. Since
Equivalence is not an instance of
Eq and equality
is not observable, both perspectives are valid.
Determines if two values are equivalent under the given equivalence relation.
Determines if all of the given values are equivalent under the given equivalence relation.
Construct the equivalence relation obtained by equating the given two values. This combines equivalence classes.