[Haskell-cafe] My try for a CoroutineT monad tranformer
mail at joachim-breitner.de
Fri Apr 25 14:15:57 EDT 2008
(for those who follow planet.haskell.org this is old news, but I thought
I’d tell the others)
I describe how I wrote a monad transformer that allows me to pause a
computation from within by returning another computation that I can use
to re-start the computation (or to throw it away if I want). I needed
this for a long running drawing computation in a gtk2hs program that I
want to pause at convenient points (to allow user interaction), and that
I need to abort when what I’m drawing is not up-to-date anymore.
The API basically consists of the function
> runCoroutineT :: Monad m => CoroutineT m () -> m (Maybe (CoroutineT m ()))
which runs the pausable computation, any Maybe returns Just the resume
action, and the function
> pause :: Monad m => CoroutineT m ()
to be used inside the computation, which pauses it.
I have put the complete module in the darcs repository that might later
also contain the GUI program at http://darcs.nomeata.de/FrakView/
What do you think of CoroutineT? Could it have been easily implemented
using the existing monad transformers? Is it useful enough so that it
should be included somewhere, and where? Are there any problems with
strictness or other tripping points that I have overlooked?
e-Mail: mail at joachim-breitner.de
Jabber-ID: nomeata at joachim-breitner.de
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 189 bytes
Desc: Dies ist ein digital signierter Nachrichtenteil
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20080425/4bb95560/attachment.bin
More information about the Haskell-Cafe