What Does the => Symbol Do in Haskell?

haskell

I'm fairly new to learning haskell, so I don't really understand the typing system when it comes to constraints. There's this weird => symbol that doesn't make sense to me. Is it actually just syntax? Or is it a type constructor? I'm not sure. Below are my thoughts about it. Can someone clarify what exactly => means in haskell?

In haskell, (->) is a type constructor, with kind * -> * -> *. This is nice, because it makes it clear why, for example, Double -> Bool has kind *. But then I wondered about types like (Integral a) => a -> a. Clearly, this has kind *, and a -> a has kind * (I think). Since Integral has kind * -> Constraint, Integral a must have kind Constraint. Then, I conclude that (=>) has kind Constraint -> * -> *. However, when I type :k (=>) in GHCi, I get an error ("parse error on input =>")! This seems to indicate that (=>) is not a type constructor. Then what is it?

GHCi also tells me that (Show List, Read List) has kind Constraint, but that (,) has kind * -> * -> *, which makes me very confused. Does (,) have two definitions? Are constraints some magical hocus-pocus that I just don't understand?

Any help is greatly appreciated.

Best Answer

The => is just there as a delimiter between context and type when you write a type signature. They aren't even saved after compilation. You can see it here: http://www.haskell.org/onlinereport/syntax-iso.html

Related Topic