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 a) -> m a

- controlIO :: MonadControlIO m => (RunInBase m IO -> IO (m a)) -> m a
- liftIOOp :: MonadControlIO m => ((a -> IO (m b)) -> IO (m c)) -> (a -> m b) -> m c
- liftIOOp_ :: MonadControlIO m => (IO (m a) -> IO (m b)) -> m a -> m b

# 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 a) -> m aSource

`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)

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 a)) -> m aSource

An often used composition: `controlIO = `

`join`

. `liftControlIO`

liftIOOp :: MonadControlIO m => ((a -> IO (m b)) -> IO (m c)) -> (a -> m b) -> m cSource

`liftIOOp`

is a particular application of `liftControlIO`

that allows
lifting control operations of type `(a -> `

(e.g. `IO`

b) -> `IO`

b`alloca`

, `withMVar v`

) to

.
`MonadControlIO`

m => (a -> m b) -> m b

`liftIOOp f = \g -> ``controlIO`

$ runInIO -> f $ runInIO . g

liftIOOp_ :: MonadControlIO m => (IO (m a) -> IO (m b)) -> m a -> m bSource

`liftIOOp_`

is a particular application of `liftControlIO`

that allows
lifting control operations of type

(e.g. `IO`

a -> `IO`

a`block`

) to

.
`MonadControlIO`

m => m a -> m a

`liftIOOp_ f = \m -> ``controlIO`

$ runInIO -> f $ runInIO m