Changes between Version 1 and Version 2 of Architecture

Show
Ignore:
Timestamp:
01/14/10 00:46:24 (5 years ago)
Author:
blamario (IP: 99.241.117.248)
Comment:

Renamed Trampoline to Coroutine to match the API

Legend:

Unmodified
Added
Removed
Modified
  • Architecture

    v1 v2  
    55== The lowest layer: trampoline-style nestable coroutines == 
    66 
    7 This layer, implemented by the Control.Concurrent.Trampoline module, provides a limited coroutine functionality in Haskell. The centerpiece of the approach is the monad transformer Trampoline, that transforms an arbitrary monadic computation into a suspendable and resumable one. The basic definition is simple: 
     7This layer, implemented by the Control.Concurrent.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: 
    88 
    99{{{ 
    10 newtype Trampoline s m r = Trampoline {bounce :: m (TrampolineState s m r)} 
     10newtype Coroutine s m r = Coroutine {resume :: m (CoroutineState s m r)} 
    1111 
    12 data TrampolineState s m r = Done r | Suspend! (s (Trampoline s m r)) 
     12data CoroutineState s m r = Done r | Suspend! (s (Coroutine s m r)) 
    1313 
    14 instance (Functor s, Monad m) => Monad (Trampoline s m) where 
    15    return x = Trampoline (return (Done x)) 
    16    t >>= f = Trampoline (bounce t >>= apply f) 
    17       where apply f (Done x) = bounce (f x) 
     14instance (Functor s, Monad m) => Monad (Coroutine s m) where 
     15   return x = Coroutine (return (Done x)) 
     16   t >>= f = Coroutine (resume t >>= apply f) 
     17      where apply f (Done x) = resume (f x) 
    1818            apply f (Suspend s) = return (Suspend (fmap (>>= f) s)) 
    1919}}} 
    2020 
    21 The Trampoline transformer type is parameterized by a functor. Here is an example of one functor particularly useful for a Trampoline computation: 
     21The Coroutine transformer type is parameterized by a functor. Here is an example of one functor particularly useful for a Coroutine computation: 
    2222 
    2323{{{ 
     
    2929== Streams == 
    3030 
    31 The next layer builds on the trampoline foundation to provide streaming computations. The main idea here is to introduce sinks and sources: 
     31The next layer builds on the coroutine foundation to provide streaming computations. The main idea here is to introduce sinks and sources: 
    3232 
    3333{{{ 
    3434data Sink (m :: * -> *) a x = Sink { 
    35    put :: forall d. (AncestorFunctor a d) => x -> Trampoline d m Bool, 
    36    canPut :: forall d. (AncestorFunctor a d) => Trampoline d m Bool 
     35   put :: forall d. (AncestorFunctor a d) => x -> Coroutine d m Bool, 
     36   canPut :: forall d. (AncestorFunctor a d) => Coroutine d m Bool 
    3737   } 
    3838 
    3939newtype Source (m :: * -> *) a x = Source { 
    40    get :: forall d. (AncestorFunctor a d) => Trampoline d m (Maybe x) 
     40   get :: forall d. (AncestorFunctor a d) => Coroutine d m (Maybe x) 
    4141   } 
    4242}}} 
     
    4646{{{ 
    4747pipe :: forall m a a1 a2 x r1 r2. (Monad m, Functor a, a1 ~ SinkFunctor a x, a2 ~ SourceFunctor a x) => 
    48         (Sink m a1 x -> Trampoline a1 m r1) -> (Source m a2 x -> Trampoline a2 m r2) -> Trampoline a m (r1, r2) 
     48        (Sink m a1 x -> Coroutine a1 m r1) -> (Source m a2 x -> Coroutine a2 m r2) -> Coroutine a m (r1, r2) 
    4949}}} 
    5050 
     
    5656 
    5757{{{ 
    58 type OpenConsumer m a d x r = AncestorFunctor a d => Source m a x -> Trampoline d m r 
    59 type OpenProducer m a d x r = AncestorFunctor a d => Sink m a x -> Trampoline d m r 
     58type OpenConsumer m a d x r = AncestorFunctor a d => Source m a x -> Coroutine d m r 
     59type OpenProducer m a d x r = AncestorFunctor a d => Sink m a x -> Coroutine d m r 
    6060type OpenTransducer m a1 a2 d x y =  
    61    (AncestorFunctor a1 d, AncestorFunctor a2 d) => Source m a1 x -> Sink m a2 y -> Trampoline d m [x] 
     61   (AncestorFunctor a1 d, AncestorFunctor a2 d) => Source m a1 x -> Sink m a2 y -> Coroutine d m [x] 
    6262type OpenSplitter m a1 a2 a3 a4 d x b = 
    6363   (AncestorFunctor a1 d, AncestorFunctor a2 d, AncestorFunctor a3 d, AncestorFunctor a4 d) => 
    64    Source m a1 x -> Sink m a2 x -> Sink m a3 x -> Sink m a4 b -> Trampoline d m [x] 
     64   Source m a1 x -> Sink m a2 x -> Sink m a3 x -> Sink m a4 b -> Coroutine d m [x] 
    6565 
    6666newtype Consumer m x r = Consumer {consume :: forall a d. OpenConsumer m a d x r}