
23 Jul
2013
23 Jul
'13
10:48 a.m.
On 23 July 2013 16:33, Louis-Guillaume Gagnon
and I don't undestand why the "Eq a =>" shows up.
Prelude> :type (==) (==) :: Eq a => a -> a -> Bool The (==) operator is a member of the typeclass Eq. This enables many different types to use the (==) operator by implementing their own instance of Eq (i.e. their own version of the (==) function). Since you're using the (==) operator in your code, the only types that can typecheck are those that have an instance of the Eq typeclass. ghci detects this and automatically adds the "Eq a =>" which is called a /class constraint/. It restricts the type variable 'a' to only those types that have an Eq instance defined. -- Denis Kasak