[Haskell-cafe] Composing functions with runST

Brian Hulley brianh at metamilk.com
Mon Jan 1 06:35:18 EST 2007


Yitzchak Gale wrote:
> Can anyone explain the following behavior (GHCi 6.6):
>
> Prelude Control.Monad.ST> runST (return 42)
> 42
> Prelude Control.Monad.ST> (runST . return) 42
>
> <interactive>:1:9:
>    Couldn't match expected type `forall s. ST s a'
>           against inferred type `m a1'
>    In the second argument of `(.)', namely `return'
>    In the expression: (runST . return) 42
>    In the definition of `it': it = (runST . return) 42

Section 7.4.8 of GHC manual states that a type variable can't be 
instantiated with a forall type, though it doesn't give any explanation why.

Hazarding a guess, I suggest it *might* be due to the fact that

    forall s. ST s a

means

    forall s. (ST s a)

whereas you'd need it to mean

    (forall s. ST s) a

in order for it to unify with (m a).

Just a guess - I'd be interested to know the real reason as well.

Brian.
-- 
http://www.metamilk.com 



More information about the Haskell-Cafe mailing list