[Haskell-cafe] Problem with forall type in type declaration

Twan van Laarhoven twanvl at gmail.com
Fri May 11 11:53:28 CEST 2012


On 04/05/12 09:08, Magicloud Magiclouds wrote:
> Hi,
>    Assuming this:
> run :: Monad IO a ->  IO a
> data Test = Test { f }
>
>    Here I'd like to set f to run, like "Test run". Then what is the type of f?
>    The confusing (me) part is that, the argument pass to f is not fixed
> on return type, like "f1 :: Monad IO ()", "f2 :: Monad IO Int". So
> "data Test a = Test { f :: Monad IO a ->  IO a} does not work.

You need to explicitly add "forall a." to the type of f. For example:

     {-# LANGUAGE PolymorphicComponents #-}
     run :: MonadIO m => m a -> IO a
     newtype Test = Test { f :: forall m a. MonadIO m a => m a -> IO a }



Twan



More information about the Haskell-Cafe mailing list