I have here a function I would like to propose for the list
module. It's a foldmap. Basically it's a map but it allows
you to pass along a variable among the different calls. Perhaps
it could be called foldmap_left such that a foldmap_right could be
implemented as well.
let foldmap f b l =
let (e, l') = List.fold_left
(fun (x, t) a -> let (x', a') = f x a in (x', a'::t)) (b, ) l
in (e, List.rev l')
An example of it's use:
foldmap (fun a e -> (a+1, e)) 0 [1;2;3] => (3, [1;2;3])
The motivation for this is that sometimes you want to map a certain
list (imagine for instance a list of statements in a compiler), but you
also want to gradually build up a functional environment as you pass
down this list.