Conditional instances
“A pair supports == if its component types do”
instance (Eq a,Eq b)=> Eq(a,b) where
(x1,y1)==(x2,y2) = x1=x2 and y1=y2
x /= y = not (x==y)
A list of a supports == if a does”
instance (Eq a)=> Eq [a] where
[] == [] = True
(x:xs) == (y:ys) = x==y and xs==ys
_ == _ = False
Previous slide
Next slide
Back to first slide
View graphic version