Changes between Version 4 and Version 5 of monadcoroutine
 Timestamp:
 03/22/10 00:07:53 (6 years ago)
Legend:
 Unmodified
 Added
 Removed
 Modified

monadcoroutine
v4 v5 1 1 2 = Packagemonadcoroutine =2 = monadcoroutine = 3 3 4 4 This library, implemented by the `Control.Monad.Coroutine` module, provides a limited coroutine functionality in Haskell. The centerpiece of the approach is the monad transformer `Coroutine`, which transforms an arbitrary monadic computation into a suspendable and resumable one. The basic definition is simple: … … 36 36 }}} 37 37 38 While these two are the most obvious suspension functors, any functor whatsoever can be used as a coroutine suspension functor. See ListSuspension, for example. 39 38 40 == Running a coroutine == 39 41 42 After a coroutine suspends, the suspension functor must be unpacked to get to the coroutine resumption. Here's an example of how the ''printer'' example could be run: 43 44 {{{ 45 printerFeeder :: Show x => [x] > Coroutine (Await x) IO () > IO () 46 printerFeeder [] _ = return () 47 printerFeeder (head:tail) printer = do p < resume printer 48 case p of Left (Await p') > printerFeeder tail (p' head) 49 Right result > return result 50 }}} 51 52 Alternatively, you can use the function `pogoStick` or `foldRun` to the same effect: 53 54 {{{ 55 printerFeeder feed printer = liftM snd $ foldRun f feed printer 56 where f (head:tail) (Await p) = (tail, p head) 57 f [] _ = ([], return ()) 58 }}}