Changes between Version 3 and Version 4 of monadcoroutine
 Timestamp:
 03/21/10 04:36:03 (8 years ago)
Legend:
 Unmodified
 Added
 Removed
 Modified

monadcoroutine
v3 v4 5 5 6 6 {{{ 7 newtype Coroutine s m r = Coroutine {resume :: m (Either (s (Coroutine s m r)) r)}7 newtype Coroutine s m r = Coroutine {resume :: m (Either (s (Coroutine s m r)) r)} 8 8 9 instance (Functor s, Monad m) => Monad (Coroutine s m) where9 instance (Functor s, Monad m) => Monad (Coroutine s m) where 10 10 return = Coroutine . return . Right 11 11 t >>= f = Coroutine (resume t >>= either (return . Left . fmap (>>= f)) (resume . f)) 12 12 }}} 13 13 14 == Suspension Functors == 15 14 16 The 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`: 15 17 16 18 {{{ 17 data Yield x y = Yield x y18 instance Functor (Yield x) where19 data Yield x y = Yield x y 20 instance Functor (Yield x) where 19 21 fmap f (Yield x y) = Yield x (f y) 20 22 }}} … … 33 35 printer = await >>= print >> printer 34 36 }}} 37 38 == Running a coroutine == 39