(* Here is the equivalent with a fold method: *) let ls = [1; 2; 3; 4; 5; 6] let comb2_fold f ls init = let rec aux ls acc = match ls with | [] -> (List.rev acc) | x::xs -> let acc = List.fold_left (fun acc y -> (f acc x y) ) acc xs in aux xs acc in aux ls init let () = let found = comb2_fold (fun acc v1 v2 -> if abs (v1 - v2) >= 4 then (v1, v2)::acc else acc ) ls [] in List.iter (fun (v1, v2) -> Printf.printf " (%d, %d)\n" v1 v2 ) found (* Result: *) (* (1, 5) (1, 6) (2, 6) *)