>>>>> Michael Thompson <practical.wis...@gmail.com> writes:

> I shouldn't have just mentioned recursive definitions, but also the use of
> the monad instance.

Yes, exactly, I found this to be the case too.  The problem is that we simply
can't know at compile-time what the next stage in the pipeline will be, once
the input stream is completed:

    instance (Monad m, Applicative m) => Monad (Stream a m) where
        return = Stream (return . Done)
        Stream step i >>= f = Stream step' (Left i)
          where
            step' (Left s) = step s >>= \case
                Done r     -> switchStream (f r)
                Skip s'    -> return $ Skip (Left s')
                Yield s' a -> return $ Yield (Left s') a
            step' (Right s) = switchStream s
    
    switchStream :: Functor m
                 => Stream a m r -> m (Step (Either s (Stream a m r)) a r)
    switchStream (Stream step i) = step i <&> \case
        Done r     -> Done r
        Skip s'    -> Skip (Right (Stream step s'))
        Yield s' a -> Yield (Right (Stream step s')) a

As you said, this probably inlines and fuses the input stream, but fails to
fuse the stream that is return by the bound function.

John

-- 
You received this message because you are subscribed to the Google Groups 
"Haskell Pipes" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to haskell-pipes+unsubscr...@googlegroups.com.
To post to this group, send email to haskell-pipes@googlegroups.com.

Reply via email to