[Haskell-cafe] Monadic tunnelling: the art of threading one monad
through another
Henning Thielemann
lemming at henning-thielemann.de
Thu Jul 12 09:26:17 EDT 2007
On Thu, 12 Jul 2007, Henning Thielemann wrote:
> On Wed, 11 Jul 2007, Jules Bean wrote:
>
> > Now, supposing we have a library function which takes a callback. As
> > an example, suppose we have a library function which reads in a file
> > and calls our callback once on each line. A typical type might look
> > like:
> >
> > forEachLine :: Handle -> (String -> IO ()) -> IO ()
> >
> > We have to provide a callback in the IO monad. But what if we don't
> > want to work in the IO monad? What if we are working in, for example,
> > a custom state monad of our own?
>
> What about writing a function with signature
>
> forEachLine :: MonadIO io => Handle -> (String -> io ()) -> IO ()
Should be
forEachLine :: MonadIO io => Handle -> (String -> io ()) -> io ()
and forEachLine must lift all IO operations to your custom monad using
liftIO.
More information about the Haskell-Cafe
mailing list