Open rightfold opened 5 years ago
λ Data.Set> data X = X Int String deriving (Show)
λ Data.Set> instance Eq X where (X a _) == (X b _) = a == b
λ Data.Set> instance Ord X where compare (X a _) (X b _) = a `compare` b
λ Data.Set> a = fromList [X 1 "A"]
λ Data.Set> b = fromList [X 1 "B"]
λ Data.Set> union a b
fromList [X 1 "A"]
λ Data.Set> union b a
fromList [X 1 "B"]
λ Data.Set> union a b == union b a
True
I don't see a problem. Your Eq
/ Ord
says they are EQ
ual.
They are equivalent according to the equivalence relation Eq (Set X), but they are not the same value. One is fromList [X 1 "A"] whereas the other one is fromList [X 1 "B"].
If you want the semilattice laws to hold with respect to Eq, rather than extensional equality, how would you describe them for the instance JoinSemiLattice (a -> b)?
JoinSemiLattice requires that join is commutative, but this is not necessarily true for the instance JoinSemiLattice (Set a) where join = union.
Consider this valid total order:
Now with:
The following do not give the same result: