@@ -167,13 +167,13 @@ foldr step acc m = go (toStream m)
167167
168168-- | Right fold with a monadic step function. See 'toList' for an example use.
169169{-# INLINE foldrM #-}
170−foldrM :: Streaming t => (a -> m b -> m b) -> m b -> t m a -> m b
170+foldrM :: (Streaming t, Monad m) => (a -> b -> m b) -> b -> t m a -> m b
171171foldrM step acc m = go (toStream m)
172172 where
173173 go m1 =
174− let stop = acc
174+ let stop = return acc
175175 yield a Nothing = step a acc
176− yield a (Just x) = step a (go x)
176+ yield a (Just x) = (go x) >>= (step a)
177177 in (runStream m1) Nothing stop yield
178178
179179-- | Scan left. A strict left fold which accumulates the result of its reduction steps inside a stream, from left.
@@ -255,7 +255,7 @@ toHandle h m = go (toStream m)
255255-- | Convert a stream into a list in the underlying monad.
256256{-# INLINABLE toList #-}
257257toList :: (Streaming t, Monad m) => t m a -> m [a]
258−toList = foldrM (\a xs -> fmap (a :) xs) (return [])
258+toList = foldrM (\a xs -> return (a : xs)) []
259259
260260-- | Take first 'n' elements from the stream and discard the rest.
261261{-# INLINE take #-}