[Haskell-cafe] ContT and ST stack

Daniel Fischer daniel.is.fischer at googlemail.com
Thu Mar 10 14:47:27 CET 2011


On Thursday 10 March 2011 14:18:24, Anakim Border wrote:
> Dear list,
> 
> I have the following (simplified) piece of code:
> 
> find :: Int -> [Int]
> find i = runST . (`runContT` return) $
>   callCC $ \escape -> do
>     return []
> 
> which used to compile correctly under GHC 6.12.3.
> 
> Now that I've switched to 7.0.2 it gets rejected with the following
> error:
> 
>     Couldn't match expected type `forall s. ST s c0'
>                 with actual type `m0 r0'
>     Expected type: ContT r0 m0 a0 -> forall s. ST s c0
>       Actual type: ContT r0 m0 a0 -> m0 r0
>     In the second argument of `(.)', namely `(`runContT` return)'
>     In the expression: runST . (`runContT` return)
> 
> 
> I'm a little bit lost at what exactly is the problem.

If memory serves correctly, it's impredicative polymorphism.

The type of (.), (b -> c) -> (a -> b) -> a -> c,  can't handle 
(x -> forall s. ST s [Int])

Previously there was an implementation of impredicative polymorphism which 
allowed GHC to handle that construct, but that has been removed (because it 
was unsatisfactory), so GHC 7 doesn't compile that anymore.

> Anyone can suggest a solution?

Parentheses.

find i = runST ((`runContT` return) $
    callCC $ \escape -> do
       return [])

> 
> Thanks!
> 
> AB



More information about the Haskell-Cafe mailing list