sw17ch / data-clist

A purely functional ring data structure for Haskell.
Other
8 stars 9 forks source link

Eq instance should imply substitutivity #18

Open klntsky opened 5 years ago

klntsky commented 5 years ago

As stated here,

if x == y = True and f is a "public" function whose return type is an instance of Eq, then f x == f y = True

Currently we have, e.g.

>  fromList [1,2,3] == fromList [2,3,1]
True
> toList (fromList [1,2,3]) == toList (fromList [2,3,1])
False

I think that the Eq instance should be just derived and current implementation should be exported as separate function. Besides, using allRotations is surely not the most optimal way of implementing the desired behavior. What if two CLists contain different sets of elements? Current implementation will check all the rotations, while it is possible to return False after finding the first element which is present in one of the given CLists but not in the other.