let rec foldr f base list = match list with [] -> base | x::xs -> f x (foldr f base xs) let rec unfoldr p f g seed = if p seed then [] else f seed :: unfoldr p f g (g seed) (* let rec map f list = match list with [] -> [] | x::xs -> f x :: (map f xs) *) let map f list = foldr (fun x l -> f x :: l) [] list let rec range min max = if min < max then min :: (range (min + 1) max) else [] let sum list = foldr (+) 0 list let prod list = foldr ( * ) 1 list