monad-control-0.2: Lift control operations, like exception catching, through monad transformers

PortabilityRequires RankNTypes
Stabilityexperimental
MaintainerBas van Dijk <v.dijk.bas@gmail.com>

Control.Monad.IO.Control

Description

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.

Synopsis

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.

Methods

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)

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 -> IO b) -> IO b (e.g. 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 IO a -> IO a (e.g. block) to MonadControlIO m => m a -> m a.

liftIOOp_ f = \m -> controlIO $ runInIO -> f $ runInIO m