on master help sign in
Annotate fold loops with INLINE_LATE
981140dHarendra Kumar
src/Streamly/Streams/StreamD/Type.hs+6
@@ -300,6 +300,7 @@ instance Monad m => Monad (Stream m) where
300foldrM :: Monad m => (a -> m b -> m b) -> m b -> Stream m a -> m b
300foldrM :: Monad m => (a -> m b -> m b) -> m b -> Stream m a -> m b
301foldrM f z (Stream step state) = go SPEC state
301foldrM f z (Stream step state) = go SPEC state
302 where
302 where
303+ {-# INLINE_LATE go #-}
303 go !_ st = do
304 go !_ st = do
304 r <- step defState st
305 r <- step defState st
305 case r of
306 case r of
@@ -312,6 +313,7 @@ foldrMx :: Monad m
312 => (a -> m x -> m x) -> m x -> (m x -> m b) -> Stream m a -> m b
313 => (a -> m x -> m x) -> m x -> (m x -> m b) -> Stream m a -> m b
313foldrMx fstep final convert (Stream step state) = convert $ go SPEC state
314foldrMx fstep final convert (Stream step state) = convert $ go SPEC state
314 where
315 where
316+ {-# INLINE_LATE go #-}
315 go !_ st = do
317 go !_ st = do
316 r <- step defState st
318 r <- step defState st
317 case r of
319 case r of
@@ -349,6 +351,7 @@ foldrS
349 -> Stream m b
351 -> Stream m b
350foldrS f final (Stream step state) = go SPEC state
352foldrS f final (Stream step state) = go SPEC state
351 where
353 where
354+ {-# INLINE_LATE go #-}
352 go !_ st = do
355 go !_ st = do
353 -- defState??
356 -- defState??
354 r <- yieldM $ step defState st
357 r <- yieldM $ step defState st
@@ -365,6 +368,7 @@ foldrT :: (Monad m, Monad (t m), MonadTrans t)
365 => (a -> t m b -> t m b) -> t m b -> Stream m a -> t m b
368 => (a -> t m b -> t m b) -> t m b -> Stream m a -> t m b
366foldrT f final (Stream step state) = go SPEC state
369foldrT f final (Stream step state) = go SPEC state
367 where
370 where
371+ {-# INLINE_LATE go #-}
368 go !_ st = do
372 go !_ st = do
369 r <- lift $ step defState st
373 r <- lift $ step defState st
370 case r of
374 case r of
@@ -383,6 +387,7 @@ foldlMx' fstep begin done (Stream step state) =
383 begin >>= \x -> go SPEC x state
387 begin >>= \x -> go SPEC x state
384 where
388 where
385 -- XXX !acc?
389 -- XXX !acc?
390+ {-# INLINE_LATE go #-}
386 go !_ acc st = acc `seq` do
391 go !_ acc st = acc `seq` do
387 r <- step defState st
392 r <- step defState st
388 case r of
393 case r of
@@ -402,6 +407,7 @@ foldlx' fstep begin done m =
402foldlM' :: Monad m => (b -> a -> m b) -> b -> Stream m a -> m b
407foldlM' :: Monad m => (b -> a -> m b) -> b -> Stream m a -> m b
403foldlM' fstep begin (Stream step state) = go SPEC begin state
408foldlM' fstep begin (Stream step state) = go SPEC begin state
404 where
409 where
410+ {-# INLINE_LATE go #-}
405 go !_ acc st = acc `seq` do
411 go !_ acc st = acc `seq` do
406 r <- step defState st
412 r <- step defState st
407 case r of
413 case r of