Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Control.Eff.Coroutine
Description
Coroutines implemented with extensible effects
Synopsis
- data Yield a (b :: k) (v :: k) where
- withCoroutine :: forall m b (r :: [Type -> Type]) w a. Monad m => b -> m (Y r w a)
- yield :: forall a b (r :: [Type -> Type]). Member (Yield a b) r => a -> Eff r b
- runC :: forall a b (r :: [Type -> Type]) w. Eff (Yield a b ': r) w -> Eff r (Y r b a)
- data Y (r :: [Type -> Type]) w a
Documentation
data Yield a (b :: k) (v :: k) where Source #
Co-routines The interface is intentionally chosen to be the same as in transf.hs
| The yield request: reporting a value of type e and suspending the coroutine. Resuming with the value of type b
Instances
Handle (Yield a b) (Yield a b ': r) w (Eff r (Y r b a)) Source # | Given a continuation and a request, respond to it |
Defined in Control.Eff.Coroutine Methods handle :: (Eff (Yield a b ': r) w -> Eff r (Y r b a)) -> Arrs (Yield a b ': r) v w -> Yield a b v -> Eff r (Y r b a) Source # handle_relay :: forall (r' :: [Type -> Type]). ((Yield a b ': r) ~ (Yield a b ': r'), Relay (Eff r (Y r b a)) r') => (w -> Eff r (Y r b a)) -> (Eff (Yield a b ': r) w -> Eff r (Y r b a)) -> Eff (Yield a b ': r) w -> Eff r (Y r b a) Source # respond_relay :: (w -> Eff r (Y r b a)) -> (Eff (Yield a b ': r) w -> Eff r (Y r b a)) -> Eff (Yield a b ': r) w -> Eff r (Y r b a) Source # |
withCoroutine :: forall m b (r :: [Type -> Type]) w a. Monad m => b -> m (Y r w a) Source #
Return a pure value
yield :: forall a b (r :: [Type -> Type]). Member (Yield a b) r => a -> Eff r b Source #
Yield a value of type a and suspend the coroutine.
runC :: forall a b (r :: [Type -> Type]) w. Eff (Yield a b ': r) w -> Eff r (Y r b a) Source #
Launch a thread and report its status
data Y (r :: [Type -> Type]) w a Source #
Status of a thread: done or reporting the value of the type a (For simplicity, a co-routine reports a value but accepts unit)
Type parameter r
is the effect we're yielding from.
Type parameter a
is the type that is yielded.
Type parameter w
is the type of the value returned from the
coroutine when it has completed.
Instances
Handle (Yield a b) (Yield a b ': r) w (Eff r (Y r b a)) Source # | Given a continuation and a request, respond to it |
Defined in Control.Eff.Coroutine Methods handle :: (Eff (Yield a b ': r) w -> Eff r (Y r b a)) -> Arrs (Yield a b ': r) v w -> Yield a b v -> Eff r (Y r b a) Source # handle_relay :: forall (r' :: [Type -> Type]). ((Yield a b ': r) ~ (Yield a b ': r'), Relay (Eff r (Y r b a)) r') => (w -> Eff r (Y r b a)) -> (Eff (Yield a b ': r) w -> Eff r (Y r b a)) -> Eff (Yield a b ': r) w -> Eff r (Y r b a) Source # respond_relay :: (w -> Eff r (Y r b a)) -> (Eff (Yield a b ': r) w -> Eff r (Y r b a)) -> Eff (Yield a b ': r) w -> Eff r (Y r b a) Source # |