Eq is a Haskell type class for comparing values. It defines equality ((==)) and inequality ((/=)); both take two values of the same type and return Bool. A value can be compared only when its type has an Eq instance. section 5.1.3
ghci> :info Eq
type Eq :: * -> Constraint
class Eq a where
(==) :: a -> a -> Bool
(/=) :: a -> a -> Bool
{-# MINIMAL (==) | (/=) #-}
Inspect Eq in GHCi to see its methods and its minimal implementation requirement: an instance needs to define either (==) or (/=). section 5.1.3
Use Eq constraints when a function compares values:
- Write Eq a => when a function uses equality on an otherwise arbitrary type a. section 5.1.4
- Compare only values of the same Eq-enabled type; an Int cannot be compared directly with a Float. section 5.1.3
- Rely on the missing comparison operation being inferred by negating the supplied one. section 5.1.3
- Use constrained instances such as Eq a => Eq (Maybe a) and Eq a => Eq [a] to compare containers when their elements are comparable. section 5.1.3
Checking membership in a graph
A membership function uses equality to search an associative list: member :: Eq a => a -> [(a, b)] -> Bool. It returns False for an empty list, compares each key with (==), and can support graph operations such as hasNode and addNode. section 5.1.4
