let rec rev_append l1 l2 =
match l1 with
[] -> l2
| a :: l -> rev_append l (a :: l2)
let rev l = rev_append l []
let find_all p =
let rec find accu = function
| [] -> rev accu
| x :: l -> if p x then find (x :: accu) l else find accu l in
find []
let filter = find_all
let rec map f = function
[] -> []
| a::l -> let r = f a in r :: map f l
let rec iter f = function
[] -> ()
| a::l -> f a; iter f l
let rec fold_right f l accu =
match l with
[] -> accu
| a::l -> f a (fold_right f l accu)