[Haskell-cafe] Composing functions with runST

Seth Gordon sethg at ropine.com
Wed Jan 3 09:31:38 EST 2007


Simon Peyton-Jones wrote:
> Conor and others are right; it's all to do with type inference.  There is nothing wrong with the program you are writing, but it's hard to design a type inference algorithm that can figure out what you are doing.
> 
> The culprit is that you want to instantiate a polymorphic function (here (.) or ($) in your examples) with a higer-rank polymorphic type (the type of runST, in this case).  That requires impredicative polymorphism and while GHC now allows that, it only allows it when it's pretty obvious what is going on --- and sadly this case is not obvious enough.

I don't know enough type theory to suggest a specific patch, but I hope
a future version of GHC can do the right thing for (.) and ($) in this
situation (and possibly for other functions that simply rearrange their
arguments, like flip).

>From a friendliness-to-newbies point of view, these error messages are a
tremendous wart.  I've been on haskell-cafe for a little over three
months and seen postings from three people who were tripped up by this
(the first of them was myself).

So I can't just tell someone who's just starting to learn Haskell that
"f $ g y" is equivalent to "f (g y)"; I have to say "those two are
*almost always* equivalent, but if you use $ and the compiler complains
about not being able to match the expected and the inferred type and a
type signature in the error message has the word 'forall', try rewriting
that expression without the $ and see if it compiles".  Eeeww.


More information about the Haskell-Cafe mailing list