Changes between Version 1 and Version 2 of monad-coroutine

Show
Ignore:
Timestamp:
03/20/10 20:24:32 (4 years ago)
Author:
blamario (IP: 99.241.117.248)
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • monad-coroutine

    v1 v2  
    22= Package monad-coroutine = 
    33 
    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, that transforms an arbitrary monadic computation into a suspendable and resumable one. The basic definition is simple: 
     4This 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: 
    55 
    66{{{ 
    7 newtype Coroutine s m r = Coroutine {resume :: m (CoroutineState s m r)} 
    8  
    9 data CoroutineState s m r = Done r | Suspend! (s (Coroutine s m r)) 
     7newtype Coroutine s m r = Coroutine {resume :: m (Either (s (Coroutine s m r)) r)} 
    108 
    119instance (Functor s, Monad m) => Monad (Coroutine s m) where 
    12    return x = Coroutine (return (Done x)) 
    13    t >>= f = Coroutine (resume t >>= apply f) 
    14       where apply f (Done x) = resume (f x) 
    15             apply f (Suspend s) = return (Suspend (fmap (>>= f) s)) 
     10   return = Coroutine . return . Right 
     11   t >>= f = Coroutine (resume t >>= either (return . Left . fmap (>>= f)) (resume . f)) 
    1612}}} 
    1713 
    18 The Coroutine transformer type is parameterized by a functor. Here is an example of one functor particularly useful for a Coroutine computation: 
     14The Coroutine transformer type is parameterized by a functor. The functor in question wraps the resumption of a suspended coroutine, and it can carry other information as well. Module `Control.Monad.Coroutine.SuspensionFunctors` exports some useful functors, one of which is `Yield`: 
    1915 
    2016{{{