[Haskell-cafe] A function synonym is not (by default) as polymorphic as the original.

Theodore Lief Gannon tanuki at gmail.com
Wed Aug 15 03:43:30 UTC 2018


Hey, I ran into this earlier today, though it was in a where clause. :)
Luckily I already knew what to google, since there are multiple ways to
handle it and I wasn't sure which was best (I went with "just give it a
signature").

You're looking at the storied Monomorphism Restriction!

https://wiki.haskell.org/Monomorphism_restriction

On Tue, Aug 14, 2018, 8:33 PM Jeffrey Brown <jeffbrown.the at gmail.com> wrote:

> Today I was writing a lot of Hashable instances, and found it hard to read
> code littered long lines mostly consisting of `hashWithSalt`, so I made a
> synonym:
>
> infixl 5 ##
> (##) = hashWithSalt
>
> But when I replaced all the `hashWithSalt`s with ##, I got lots of weird
> errors -- GHC kept wanting things to be Strings that were Ints, or vice
> verse. The problem vanished when I added this type signature:
>
> (##) :: Hashable a => Int -> a -> Int
>
> That's exactly the same type signature that hashWithSalt has.
>
> Is this expected behavior? Desirable?
>
>
> --
> Jeff Brown | Jeffrey Benjamin Brown
> Website <https://msu.edu/~brown202/>   |   Facebook
> <https://www.facebook.com/mejeff.younotjeff>   |   LinkedIn
> <https://www.linkedin.com/in/jeffreybenjaminbrown>(spammy, so I often
> miss messages here)   |   Github <https://github.com/jeffreybenjaminbrown>
>
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20180814/f1ddcf4d/attachment.html>


More information about the Haskell-Cafe mailing list