@@ -839,39 +839,42 @@ liftInner (Stream step state) = Stream step' state
839839 Stop -> Stop
840840
841841{-# INLINE_NORMAL runReaderT #-}
842−runReaderT :: Monad m => s -> Stream (ReaderT s m) a -> Stream m a
843−runReaderT sval (Stream step state) = Stream step' state
842+runReaderT :: Monad m => m s -> Stream (ReaderT s m) a -> Stream m a
843+runReaderT env (Stream step state) = Stream step' (state, env)
844844 where
845845 {-# INLINE_LATE step' #-}
846− step' gst st = do
847− r <- Reader.runReaderT (step (adaptState gst) st) sval
846+ step' gst (st, action) = do
847+ sv <- action
848+ r <- Reader.runReaderT (step (adaptState gst) st) sv
848849 return $ case r of
849− Yield x s -> Yield x s
850− Skip s -> Skip s
850+ Yield x s -> Yield x (s, return sv)
851+ Skip s -> Skip (s, return sv)
851852 Stop -> Stop
852853
853854{-# INLINE_NORMAL evalStateT #-}
854−evalStateT :: Monad m => s -> Stream (StateT s m) a -> Stream m a
855−evalStateT sval (Stream step state) = Stream step' (state, sval)
855+evalStateT :: Monad m => m s -> Stream (StateT s m) a -> Stream m a
856+evalStateT initial (Stream step state) = Stream step' (state, initial)
856857 where
857858 {-# INLINE_LATE step' #-}
858− step' gst (st, sv) = do
859+ step' gst (st, action) = do
860+ sv <- action
859861 (r, sv') <- State.runStateT (step (adaptState gst) st) sv
860862 return $ case r of
861− Yield x s -> Yield x (s, sv')
862− Skip s -> Skip (s, sv')
863+ Yield x s -> Yield x (s, return sv')
864+ Skip s -> Skip (s, return sv')
863865 Stop -> Stop
864866
865867{-# INLINE_NORMAL runStateT #-}
866−runStateT :: Monad m => s -> Stream (StateT s m) a -> Stream m (s, a)
867−runStateT sval (Stream step state) = Stream step' (state, sval)
868+runStateT :: Monad m => m s -> Stream (StateT s m) a -> Stream m (s, a)
869+runStateT initial (Stream step state) = Stream step' (state, initial)
868870 where
869871 {-# INLINE_LATE step' #-}
870− step' gst (st, sv) = do
872+ step' gst (st, action) = do
873+ sv <- action
871874 (r, sv') <- State.runStateT (step (adaptState gst) st) sv
872875 return $ case r of
873− Yield x s -> Yield (sv', x) (s, sv')
874− Skip s -> Skip (s, sv')
876+ Yield x s -> Yield (sv', x) (s, return sv')
877+ Skip s -> Skip (s, return sv')
875878 Stop -> Stop
876879
877880------------------------------------------------------------------------------