Typeclasses in Haskell
1. Typeclasses
Think of Java Interfaces. A typeclass defines behavior that all members of the typeclass must adhere to.
For example, all instances of the Eq
typeclass must implement the ==
method.
Eq
is declared as follows:
class Eq a where (==) :: a -> a -> bool
This says that a type a
is an instance of Eq
if it implements the method ==
with the given type.