(* The map function: *) let ls = [ 1.0; 2.0; 3.0; 4.0; 5.0; 6.0 ] let comb2_map f ls = let rec aux ls acc = match ls with | [] -> (List.rev acc) | x::xs -> let x, ys = List.fold_left (fun (x, ys) y -> let x, y = (f x y) in (x, y::ys) ) (x, []) xs in aux (List.rev ys) (x::acc) in aux ls [] let () = let fs = comb2_map (fun v1 v2 -> match (v1, v2) with | (5.0, 4.0) | (4.0, 5.0) -> (4.0 -. 0.2, 5.0 +. 0.2) | orig -> orig ) ls in List.iter (fun (v) -> Printf.printf " (%g)\n" v ) fs (* Reslut: *) (* (1) (2) (3) (3.8) (5.2) (6) *)