-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A monad transformer that turns event processing into co-routine programming. -- -- Task monad transformer can help refactor event and callback heavy -- programs into monads via co-routines. The idea is loosely based on -- Combining Events And Threads For Scalable Network Services, by -- Peng Li and Steve Zdancewic, in PLDI, 2007. -- (http://www.cis.upenn.edu/~stevez/papers/abstracts.html#LZ07), -- but with deterministic and co-operative lightweight threads, also -- known as co-routines, so that the base monad can be anything ranging -- from IO to state monads, or your favorite monad transformer stack. @package monad-task @version 0.2.0 -- | The MonadTask class that defines the set of combinators to work with -- Task monad. -- -- The operations for MonadTask are similar to those of co-routines, with -- the addition of watching and signaling events. -- -- We also define a set of auto lifting for common transformers. Note -- that we purposely leave a case undefined where a state transformer -- goes on top of a task monad, because such an operation is either -- unsound or has to roll back the state (see -- liftCallCC). So it's recommended to keep TaskT on top -- of all StateT in a transformer stack. module Control.Monad.Task.Class -- | MonadTask specifies a task monad m over an event -- type e. class Monad m => MonadTask e m | m -> e -- | yield temporarily suspends current task to let others run. yield :: MonadTask e m => m () -- | fork spawns a task and runs it immediately until it ends or -- suspends before returning to current task. fork :: MonadTask e m => m a -> m () -- | watch suspends the current task to wait for future events, -- and will resume execution when an event triggers its watching -- function. watch :: MonadTask e m => (e -> Maybe a) -> m a -- | signal broadcasts an event to all other tasks that are -- watching, and give those who wake up the priority to run. signal :: MonadTask e m => e -> m () -- | exit ends all tasks and returns immediately. exit :: MonadTask e m => m () -- | orElse is a helper function for combining two trigger -- functions disjuctively, favoring the first one. orElse :: (e -> Maybe a) -> (e -> Maybe b) -> e -> Maybe (Either a b) instance (GHC.Base.Monad m, Control.Monad.Task.Class.MonadTask a m) => Control.Monad.Task.Class.MonadTask a (Control.Monad.Trans.Except.ExceptT e m) instance (GHC.Base.Monad m, Control.Monad.Task.Class.MonadTask a m) => Control.Monad.Task.Class.MonadTask a (Control.Monad.Trans.Identity.IdentityT m) instance (GHC.Base.Monad m, Control.Monad.Task.Class.MonadTask a m) => Control.Monad.Task.Class.MonadTask a (Control.Monad.Trans.List.ListT m) instance (GHC.Base.Monad m, Control.Monad.Task.Class.MonadTask a m) => Control.Monad.Task.Class.MonadTask a (Control.Monad.Trans.Maybe.MaybeT m) instance (GHC.Base.Monad m, Control.Monad.Task.Class.MonadTask a m) => Control.Monad.Task.Class.MonadTask a (Control.Monad.Trans.Reader.ReaderT r m) instance (GHC.Base.Monoid w, GHC.Base.Monad m, Control.Monad.Task.Class.MonadTask a m) => Control.Monad.Task.Class.MonadTask a (Control.Monad.Trans.Writer.Lazy.WriterT w m) instance (GHC.Base.Monoid w, GHC.Base.Monad m, Control.Monad.Task.Class.MonadTask a m) => Control.Monad.Task.Class.MonadTask a (Control.Monad.Trans.Writer.Strict.WriterT w m) module Control.Monad.Trans.Task -- | Task monad transformer. newtype TaskT e m a TaskT :: ContT (Trace m e) m a -> TaskT e m a [runTaskT] :: TaskT e m a -> ContT (Trace m e) m a -- | A Trace m e represents the control flow of a mult-threaded -- task monad defined over a base monad m and event type -- e. data Trace m e [EXIT] :: Trace m e [RET] :: Trace m e [YIELD] :: m (Trace m e) -> Trace m e [FORK] :: m (Trace m e) -> m (Trace m e) -> Trace m e [WATCH] :: (e -> Maybe v) -> (v -> m (Trace m e)) -> Trace m e [SIGNAL] :: e -> m (Trace m e) -> Trace m e -- | runTrace runs a trace to its completion in the base monad -- with a simple round-robin scheduler. runTrace :: Monad m => m (Trace m e) -> m () -- | tasktoTrace CPS-converts a task monad into a trace in its -- base monad. taskToTrace :: Monad m => TaskT e m a -> m (Trace m e) -- | runTask runs a task monad until to its completion, i.e., no -- more active tasks to run, or until it exits. -- --
runTask = runTrace . -- taskToTrace
runTask = runTrace . -- taskToTrace