蓄積しつつ,畳み込む.

foldL :: (a -> b -> c -> c) -> c -> (a -> b -> a) -> a -> [b] -> c
foldL f c g a (x:xs) = f a x (foldList f c g (g a x) xs)
foldL _ c _ _ _      = c

先日のtakeWhileAcc は foldL のインスタンス

takeWhileAcc :: (a -> b -> Bool) -> (a -> b -> a) -> a -> [b] -> [b]
takeWhileAcc p f z = foldL (\ a b c -> if p a b then b:c else []) f z

foldr や foldl も foldL のインスタンス

foldr f z = foldL f' z undefined undefined
  where f' = const f
foldl g z = flip (foldL g' id undefined undefined) z
  where g' = const (flip (.) . flip g)

mapAccumL はいかにも foldL のインスタンスだね.mapAccumRはどう?mapAccumRを考えるとfoldLはもうすこし一般化できそうだよね。