Instances of type classes
Types explicitly declared as members of particular type classes
Use instance construct
They must provide implementations of the type class’ operations
instance Eq Int where
x == y = intEq x y
x /= y = intNeq x y
instance Eq Float where
x == y = floatEq x y
x /= y = floatNeq x y
3 == 4 -–allowed
3.4 /= 5.6 --allowed
3 == 4.5 --type error
“hi” == “there” –-type error
Previous slide
Next slide
Back to first slide
View graphic version