Safe Haskell | None |
---|---|

Language | Haskell98 |

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.

Besides, Task monad transformer also provides a simple mechanism to signal and watch for events, which allows complex event processing logic to be expressed as streamlined monadic co-routines.

Task monad transformer is essentially a ContT, or continuation transformer, defined to extract the control flow of monadic programs with co-operative multi-threading. After the CPS transformation, the program trace is then executed with a simple round-robin scheduler.

# MonadTask class

class Monad m => MonadTask e m | m -> e where Source #

`MonadTask`

specifies a task monad `m`

over an event type `e`

.

`yield`

temporarily suspends current task to let others run.

`fork`

spawns a task and runs it immediately until it ends or
suspends before returning to current task.

watch :: (e -> Maybe a) -> m a Source #

`watch`

suspends the current task to wait for future events, and will
resume execution when an event triggers its watching function.

`signal`

broadcasts an event to all other tasks that are watching,
and give those who wake up the priority to run.

`exit`

ends all tasks and returns immediately.

(Monad m, MonadTask a m) => MonadTask a (MaybeT m) Source # | |

(Monad m, MonadTask a m) => MonadTask a (ListT m) Source # | |

(Monoid w, Monad m, MonadTask a m) => MonadTask a (WriterT w m) Source # | |

(Monoid w, Monad m, MonadTask a m) => MonadTask a (WriterT w m) Source # | |

(Monad m, MonadTask a m) => MonadTask a (IdentityT * m) Source # | |

(Monad m, MonadTask a m) => MonadTask a (ExceptT e m) Source # | |

Monad m => MonadTask e (TaskT e m) Source # | |

(Monad m, MonadTask a m) => MonadTask a (ReaderT * r m) Source # | |

# TaskT monad transformer

Task monad transformer.

MonadState s m => MonadState s (TaskT e m) Source # | |

MonadReader s m => MonadReader s (TaskT e m) Source # | |

Monad m => MonadTask e (TaskT e m) Source # | |

MonadTrans (TaskT e) Source # | |

Monad m => Monad (TaskT e m) Source # | |

Functor (TaskT e m) Source # | |

Applicative (TaskT e m) Source # | |

MonadIO m => MonadIO (TaskT e m) Source # | |