Portability | Requires RankNTypes |
---|---|
Stability | experimental |
Maintainer | Bas van Dijk <v.dijk.bas@gmail.com> |
This module defines the class MonadControlIO
of IO
-based monads into
which control operations on IO
(such as exception catching; see
Control.Exception.Control) can be lifted.
liftIOOp
and liftIOOp_
enable convenient lifting of two common
special cases of control operation types.
- class MonadIO m => MonadControlIO m where
- liftControlIO :: (RunInBase m IO -> IO α) -> m α
- controlIO :: MonadControlIO m => (RunInBase m IO -> IO (m α)) -> m α
- liftIOOp :: MonadControlIO m => ((α -> IO (m β)) -> IO (m γ)) -> (α -> m β) -> m γ
- liftIOOp_ :: MonadControlIO m => (IO (m α) -> IO (m β)) -> m α -> m β
Documentation
class MonadIO m => MonadControlIO m whereSource
MonadControlIO
is the class of IO
-based monads supporting an
extra operation liftControlIO
, enabling control operations on IO
to be
lifted into the monad.
liftControlIO :: (RunInBase m IO -> IO α) -> m αSource
liftControlIO
is a version of liftControl
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 to lift control operations on IO
into any
monad in MonadControlIO
. For example:
foo ::IO
a ->IO
a foo' ::MonadControlIO
m => m a -> m a foo' a =controlIO
$ runInIO -> -- runInIO :: m a ->IO
(m a) foo $ runInIO a -- uses foo ::IO
(m a) ->IO
(m a)
Instances should satisfy similar laws as the MonadIO
laws:
liftControlIO . const . return = return
liftControlIO (const (m >>= f)) = liftControlIO (const m) >>= liftControlIO . const . f
Additionally instances should satisfy:
controlIO
$ \runInIO -> runInIO m = m
MonadControlIO IO | |
MonadControlIO m => MonadControlIO (MaybeT m) | |
MonadControlIO m => MonadControlIO (ListT m) | |
MonadControlIO m => MonadControlIO (IdentityT m) | |
(Monoid w, MonadControlIO m) => MonadControlIO (WriterT w m) | |
(Monoid w, MonadControlIO m) => MonadControlIO (WriterT w m) | |
MonadControlIO m => MonadControlIO (StateT s m) | |
MonadControlIO m => MonadControlIO (StateT s m) | |
MonadControlIO m => MonadControlIO (ReaderT r m) | |
(Error e, MonadControlIO m) => MonadControlIO (ErrorT e m) | |
(Monoid w, MonadControlIO m) => MonadControlIO (RWST r w s m) | |
(Monoid w, MonadControlIO m) => MonadControlIO (RWST r w s m) |
controlIO :: MonadControlIO m => (RunInBase m IO -> IO (m α)) -> m αSource
An often used composition: controlIO =
join
. liftControlIO
liftIOOp :: MonadControlIO m => ((α -> IO (m β)) -> IO (m γ)) -> (α -> m β) -> m γSource
liftIOOp
is a particular application of liftControlIO
that allows
lifting control operations of type (a ->
(e.g. IO
b) -> IO
balloca
, withMVar v
) to
.
MonadControlIO
m => (a -> m b) -> m b
liftIOOp f = \g -> controlIO
$ runInIO -> f $ runInIO . g
liftIOOp_ :: MonadControlIO m => (IO (m α) -> IO (m β)) -> m α -> m βSource
liftIOOp_
is a particular application of liftControlIO
that allows
lifting control operations of type
(e.g. IO
a -> IO
ablock
) to
.
MonadControlIO
m => m a -> m a
liftIOOp_ f = \m -> controlIO
$ runInIO -> f $ runInIO m