I am Coroutine package for educational purposes, here it is:
data Step abr = Stop | Yield br | Await (a -> r) instance Functor (Step ab) where fmap gs = case s of Stop -> Stop Yield br -> Yield b $ gr Await f -> Await (g . f) data CoroutineT mab = CoT { resume :: m (Step ab (CoroutineT mab)) } run_ :: Monad m => CoroutineT mab -> [a] -> m [b] run_ (CoT m) as = m >>= \step -> case step of Stop -> return [] Yield or -> liftM (o:) $ run_ r as Await k -> case is of [] -> return [] (x:xs) -> run_ (kx) xs instance Monad m => Functor (CoroutineT ma) where fmap g (CoT m) = CoT $ liftM ap m where ap Stop = Stop ap (Yield br) = Yield (gb) (fmap gr) ap (Await k) = Await $ (fmap g) . k instance Monad m => Monad (CoroutineT ma) where return b = CoT . return . Yield b $ return b (CoT m) >>= g = CoT $ liftM go m where go Stop = Stop go (Yield br) = undefined
As you can see in the comments above, the only line that I came across with the Yield event, I see that
(>>=) :: CoroutineT mab -> (b -> CoroutineT mac) -> CoroutineT mac (gb) :: CoroutineT mac r :: CoroutineT mab (r >>= g) :: CoroutineT mac
But I'm not sure
- How to get them together so they print checks.
- What is
bind semantics in the case of Yield
source share