@@ -706,43 +706,44 @@ serialWith func (Fold stepL initialL extractL) (Fold stepR initialR extractR) =
706706 return $ func rL rR
707707 Done rR -> return $ func rL rR
708708
709+{-# ANN type Step Fuse #-}
710+data SeqFoldState_ sl sr = SeqFoldL_ !sl | SeqFoldR_ !sr
711+
709712-- | Same as applicative '*>'. Run two folds serially one after the other
710713-- discarding the result of the first.
711714--
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.
718+--
712719{-# 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
715721serial_ (Fold stepL initialL _) (Fold stepR initialR extractR) =
716722 Fold step initial extract
717723
718724 where
719725
720− func _ b = b
721−
722726 initial = do
723727 resL <- initialL
724728 case resL of
725− Partial sl -> return $ Partial $ SeqFoldL sl
726− Done bl -> do
729+ Partial sl -> return $ Partial $ SeqFoldL_ sl
730+ Done _ -> do
727731 resR <- initialR
728− return $ first (SeqFoldR (func bl)) resR
732+ return $ first SeqFoldR_ resR
729733
730− step (SeqFoldL st) a = do
734+ step (SeqFoldL_ st) a = do
731735 r <- stepL st a
732736 case r of
733− Partial s -> return $ Partial (SeqFoldL s)
734− Done b -> do
735− res <- initialR
736− return $ first (SeqFoldR (func b)) res
737− step (SeqFoldR f st) a = do
738− r <- stepR st a
739− return $
740− case r of
741− Partial s -> Partial (SeqFoldR f s)
742− Done b -> Done b
737+ Partial s -> return $ Partial (SeqFoldL_ s)
738+ Done _ -> do
739+ resR <- initialR
740+ return $ first SeqFoldR_ resR
741+ step (SeqFoldR_ st) a = do
742+ resR <- stepR st a
743+ return $ first SeqFoldR_ resR
743744
744− extract (SeqFoldR _ sR) = extractR sR
745− extract (SeqFoldL _) = do
745+ extract (SeqFoldR_ sR) = extractR sR
746+ extract (SeqFoldL_ _) = do
746747 res <- initialR
747748 case res of
748749 Partial sR -> extractR sR