Type classes provide a very good abstraction for defining common behavior across data types. For example, the Eq type class is defined as follows:
class Eq a where (==) :: a -> a -> Bool (/=) :: a -> a -> Bool
The preceding type class defines a set of behavior for type a. The behavior is a set of functions. The Eq class specifies two functions, equality (==) and non-equality (/=). Both functions take two arguments of type a and return Bool.
The standard Haskell provides definition for both (==) and (/=) as follows:
x == y = not (x /= y) -- Note the definition of (==) by in-fix notation. x /= y = not (x == y)
You can see that the behavior of equality is defined in terms of non-equality and vice versa. To be able to provide ...