[Haskell-cafe] existential type problem

Koji Nakahara yu- at div.club.ne.jp
Fri Oct 15 21:19:14 EDT 2004


On Fri, 15 Oct 2004 19:55:02 -0400
Andrew Pimlott <andrew at pimlott.net> wrote:

>     data Foo = forall t. (MonadTrans t) => Foo
>                     ((Monad m, Monad (t m)) => t m a -> m a)    -- run
>                     ((Monad m, Monad (t m)) => t m Int)         -- op
> 
>     prog :: Foo -> IO Int
>     prog (Foo run op) = run $ do
>       lift $ putStrLn "Running prog"
>       op
> 
> ghci gives the error
> 
>     Could not deduce (Monad (t IO)) from the context (MonadTrans t)
>       arising from use of `op' at try.hs:22


Your prog leaks m (= IO) out of Foo.  I guess you mean:

> data Foo m = forall t. (MonadTrans t, Monad (t m)) =>
>       Foo (forall a. t m a -> m a) (t m Int)
> 
> prog :: Foo IO -> IO Int
> prog (Foo run op) = run $ do
>       lift $ putStrLn "Running prog"
>       op
> 
> test = prog (Foo (flip evalStateT 0) get)

--
Koji Nakahara


More information about the Haskell-Cafe mailing list