[Haskell-cafe] "runST $ return ()" /= "runST (return ())" ??

Stefan O'Rear stefanor at cox.net
Sat Mar 24 20:33:55 EDT 2007


On Sun, Mar 25, 2007 at 01:28:53AM +0100, Marc A. Ziegert wrote:
> hi!
> 
> i've just discovered this strange behaviour of existential quantifiers with runST:
> 
> ---
> Prelude Control.Monad.ST> :t runST (return ())
> runST (return ()) :: ()
> 
> Prelude Control.Monad.ST> :t runST $ (return ())
> <interactive>:1:9:
>     Couldn't match expected type `forall s. ST s a'
>            against inferred type `m ()'
>     In the second argument of `($)', namely `(return ())'
> 
> Prelude Control.Monad.ST>
> ---
> 
> 
> the same with "id runST undefined".
> is this a bug or an unsolved problem?
> i'm not sure wheather it is a part of the wanted feature of runST's type definition.
> 
> i did not find any discussions about this.
> can anyone enlighten me, please?

Neither.  The type of id is:

forall a. a -> a

In Haskell, type variables range only over normal types, not rank-two
types.  Therefore the application (runST id) is illegal.  (Sadly GHC
is not able to produce a particularly good error message in this
case.)

(There is a GHC extension in the HEAD that allows this, but you are
adviced not to rely on or even try to understand it.)

Stefna


More information about the Haskell-Cafe mailing list