[Haskell-beginners] Why do i need to specify the class of a here at all?

mrx patrik.mrx at gmail.com
Thu Nov 23 08:18:05 UTC 2017


On Wed, Nov 22, 2017 at 10:40 PM, Quentin Liu <quentin.liu.0415 at gmail.com>
wrote:

> Hi Patrik,
>
> The reason for the requirement of “Eq a” in your `sortListOfLists` is that
> you are calling myOrderFunc which carries the signature “Eq a”. If you
> remove the `Eq` declaration in `myOrderFunc` the compiler then would not
> complain about the absence of `Eq` in `sortListOfLists`. For a detailed
> explanation you could reference chapter 6 of Real World Haskell.
>

Thanks a lot for the reference. I'll make sure to read that chapter soon.


>
> Yes, you could pass the function a list of strings as well. A string is
> just a list of Chars. The type signature `a` does not restrict the range of
> types you could pass to the function.
>

That seem strange to me. Wouldn't that mean that i could write the
declaration of myOrderFunc as `myOrderFunc :: a -> a -> Ordering` as well?
GHCI give me an error on this though so obviously it's wrong. I just don't
see why. Why cannot a represent [b]?

// Patrik
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20171123/9eb5ea0c/attachment.html>


More information about the Beginners mailing list