(* * * * * * * * * * * * Resource Aware ML * * * * * * * * * * * * * * * * Use Cases * * * * File: * example/list_map.raml * * Author: * Jan Hoffmann, Shu-Chun Weng (2014) * * Description: * Some variations of list map. * *) (* The usual list map function. *) let rec map f l = match l with | [] -> [] | x::xs -> let ys = map f xs in (f x)::ys (* The usual list rev_map function. *) let map_rev f l = let rec rmap l acc = match l with | [] -> acc | x::xs -> let acc' = (f x)::acc in rmap xs acc' in rmap l [] (* Iteratively apply two functional arguments. *) let map_rev2 f1 f2 l = let rec rmap1 l acc = match l with | [] -> acc | x::xs -> rmap2 xs ((f1 x) :: acc) and rmap2 l acc = match l with | [] -> acc | x::xs -> rmap1 xs ((f2 x) :: acc) in rmap1 l [] ;; ()