[Haskell-cafe] IO within parser
Malte Milatz
malte at gmx-topmail.de
Sun Aug 12 03:09:26 EDT 2007
Gregory Propf, Sat, 11 Aug 2007 13:06:43 -0700:
> but the type of liftIO is baffling
>
> class Monad m => MonadIO m where
> liftIO :: IO a -> m a
>
> But how do you define this function? There is no constructor for "IO a" that you can "take apart".
If not using unsafePerformIO, which is usually not what we want, the
monad m in question must incorporate IO. That is, it could be defined
something like (say we want a parser with state):
newtype IOParser tok s a
= IOParser (s -> [tok] -> IO (s,a))
You can then define liftIO without “taking apart” the IO value; instead
you put liftIO's IO action (IO a) into IOParser's IO action (IO
(s,a)). Parsec does not define any such parser, though, so there's
nothing for which you may define an instance of MonadIO.
Malte
More information about the Haskell-Cafe
mailing list