Changes between Version 4 and Version 5 of monad-coroutine

Show
Ignore:
Timestamp:
03/22/10 00:07:53 (4 years ago)
Author:
blamario (IP: 99.241.117.248)
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • monad-coroutine

    v4 v5  
    11 
    2 = Package monad-coroutine = 
     2= monad-coroutine = 
    33 
    44This 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: 
     
    3636}}} 
    3737 
     38While these two are the most obvious suspension functors, any functor whatsoever can be used as a coroutine suspension functor. See ListSuspension, for example. 
     39 
    3840== Running a coroutine == 
    3941 
     42After 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 
     52Alternatively, 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}}}