-> mapAccumR :: (acc -> x -> (acc, y)) -- Function of elt of input list
-> -- and accumulator, returning new
-> -- accumulator and elt of result list
-> -> acc -- Initial accumulator
-> -> [x] -- Input list
-> -> (acc, [y]) -- Final accumulator and result list
->
-> mapAccumR f b [] = (b, [])
-> mapAccumR f b (x:xs) = (b'', x':xs') where
-> (b'', x') = f b' x
-> (b', xs') = mapAccumR f b xs
-
-> mapAccumL :: (acc -> x -> (acc, y)) -- Function of elt of input list
-> -- and accumulator, returning new
-> -- accumulator and elt of result list
-> -> acc -- Initial accumulator
-> -> [x] -- Input list
-> -> (acc, [y]) -- Final accumulator and result list
->
-> mapAccumL f b [] = (b, [])
-> mapAccumL f b (x:xs) = (b'', x':xs') where
-> (b', x') = f b x
-> (b'', xs') = mapAccumL f b' xs
-
-Here is the bi-directional version ...
-
-> mapAccumB :: (accl -> accr -> x -> (accl, accr,y))
-> -- Function of elt of input list
-> -- and accumulator, returning new
-> -- accumulator and elt of result list
-> -> accl -- Initial accumulator from left
-> -> accr -- Initial accumulator from right
-> -> [x] -- Input list
-> -> (accl, accr, [y]) -- Final accumulator and result list
->
-> mapAccumB f a b [] = (a,b,[])
-> mapAccumB f a b (x:xs) = (a'',b'',y:ys)
-> where
-> (a',b'',y) = f a b' x
-> (a'',b',ys) = mapAccumB f a' b xs
-
-
-> assert False x = error "assert Failed"
-> assert True x = x