@@ -706,43 +706,44 @@ serialWith func (Fold stepL initialL extractL) (Fold stepR initialR extractR) =
706 return $ func rL rR
706 return $ func rL rR
707 Done rR -> return $ func rL rR
707 Done rR -> return $ func rL rR
709+{-# ANN type Step Fuse #-}
710+data SeqFoldState_ sl sr = SeqFoldL_ !sl | SeqFoldR_ !sr
709-- | Same as applicative '*>'. Run two folds serially one after the other
712-- | Same as applicative '*>'. Run two folds serially one after the other
710-- discarding the result of the first.
713-- discarding the result of the first.
715+-- This was written in the hope that it might be faster than implementing it
716+-- using serialWith, but the current benchmarks show that it has the same
717+-- performance. So do not expose it unless some benchmark shows benefit.
712{-# INLINE serial_ #-}
719{-# INLINE serial_ #-}
713−serial_ :: Monad m =>
714− Fold m x a -> Fold m x b -> Fold m x b
720+serial_ :: Monad m => Fold m x a -> Fold m x b -> Fold m x b
715serial_ (Fold stepL initialL _) (Fold stepR initialR extractR) =
721serial_ (Fold stepL initialL _) (Fold stepR initialR extractR) =
716 Fold step initial extract
722 Fold step initial extract
722 initial = do
726 initial = do
723 resL <- initialL
727 resL <- initialL
724 case resL of
728 case resL of
725− Partial sl -> return $ Partial $ SeqFoldL sl
729+ Partial sl -> return $ Partial $ SeqFoldL_ sl
726− Done bl -> do
730+ Done _ -> do
727 resR <- initialR
731 resR <- initialR
728− return $ first (SeqFoldR (func bl)) resR
732+ return $ first SeqFoldR_ resR
730− step (SeqFoldL st) a = do
734+ step (SeqFoldL_ st) a = do
731 r <- stepL st a
735 r <- stepL st a
732 case r of
736 case r of
733− Partial s -> return $ Partial (SeqFoldL s)
737+ Partial s -> return $ Partial (SeqFoldL_ s)
734− Done b -> do
738+ Done _ -> do
735− res <- initialR
739+ resR <- initialR
736− return $ first (SeqFoldR (func b)) res
740+ return $ first SeqFoldR_ resR
737− step (SeqFoldR f st) a = do
741+ step (SeqFoldR_ st) a = do
738− r <- stepR st a
742+ resR <- stepR st a
739− return $
743+ return $ first SeqFoldR_ resR
741− Partial s -> Partial (SeqFoldR f s)
744− extract (SeqFoldR _ sR) = extractR sR
745+ extract (SeqFoldR_ sR) = extractR sR
745− extract (SeqFoldL _) = do
746+ extract (SeqFoldL_ _) = do
746 res <- initialR
747 res <- initialR
747 case res of
748 case res of
748 Partial sR -> extractR sR
749 Partial sR -> extractR sR