Portability | portable |
---|---|
Stability | experimental |
Maintainer | Anders Kaseorg <andersk@mit.edu> |
This module defines the class MonadPeelIO
of IO
-based monads into
which control operations on IO
(such as exception catching; see
Control.Exception.Peel) can be lifted.
liftIOOp
and liftIOOp_
enable convenient lifting of two common
special cases of control operation types.
- class MonadIO m => MonadPeelIO m where
- liftIOOp :: MonadPeelIO m => ((a -> IO (m b)) -> IO (m c)) -> (a -> m b) -> m c
- liftIOOp_ :: MonadPeelIO m => (IO (m a) -> IO (m b)) -> m a -> m b
Documentation
class MonadIO m => MonadPeelIO m whereSource
MonadPeelIO
is the class of IO
-based monads supporting an
extra operation peelIO
, enabling control operations on IO
to be
lifted into the monad.
peelIO :: m (m a -> IO (m a))Source
peelIO
is a version of peel
that operates through an
arbitrary stack of monad transformers directly to an inner IO
(analagously to how liftIO
is a version of lift
). So it can
be used with liftIO
to lift control operations on IO
into any
monad in MonadPeelIO
. For example:
foo ::IO
a ->IO
a foo' ::MonadPeelIO
m => m a -> m a foo' a = do k <-peelIO
-- k :: m a -> IO (m a)join
$liftIO
$ foo (k a) -- uses foo ::IO
(m a) ->IO
(m a)
Note that the "obvious" term of this type (peelIO =
) does not work correctly. Instances of return
return
MonadPeelIO
should be constructed via MonadTransPeel
, using peelIO =
.
liftPeel
peelIO
MonadPeelIO IO | |
MonadPeelIO m => MonadPeelIO (MaybeT m) | |
MonadPeelIO m => MonadPeelIO (ListT m) | |
MonadPeelIO m => MonadPeelIO (IdentityT m) | |
(Monoid w, MonadPeelIO m) => MonadPeelIO (WriterT w m) | |
(Monoid w, MonadPeelIO m) => MonadPeelIO (WriterT w m) | |
MonadPeelIO m => MonadPeelIO (StateT s m) | |
MonadPeelIO m => MonadPeelIO (StateT s m) | |
MonadPeelIO m => MonadPeelIO (ReaderT r m) | |
(Error e, MonadPeelIO m) => MonadPeelIO (ErrorT e m) | |
(Monoid w, MonadPeelIO m) => MonadPeelIO (RWST r w s m) | |
(Monoid w, MonadPeelIO m) => MonadPeelIO (RWST r w s m) |
liftIOOp :: MonadPeelIO m => ((a -> IO (m b)) -> IO (m c)) -> (a -> m b) -> m cSource