[Haskell-beginners] Type signature question

Denis Kasak denis.kasak at gmail.com
Tue Jul 23 16:48:21 CEST 2013


On 23 July 2013 16:33, Louis-Guillaume Gagnon
<louis.guillaume.gagnon at gmail.com> wrote:
>
> 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




More information about the Beginners mailing list