open List let rec foldl f x l = match l with | [] -> x | hd::tl -> foldl f (f x hd) tl let rec foldr f x l = match l with | [] -> x | hd::tl -> f hd (foldr f x tl) let rec map f l = match l with | [] -> [] | hd::tl -> (f hd)::(map f tl) let rec iter f l = match l with | [] -> () | hd::tl -> (f hd ; iter f tl) let print_list f l = let fn x = (f x; print_string " ") in print_string "[ "; iter fn l; print_string "]" let nl = print_newline