From 8dc4d5a706f2504f547f9093f151238406414785 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Wed, 20 Dec 2023 14:36:35 -0500 Subject: [PATCH] fix: overshoot, concat_map is only TRMC after 5.1 --- src/core/CCList.ml | 4 ++-- tests/core/t_list.ml | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/core/CCList.ml b/src/core/CCList.ml index 02ec4384..e8b5be45 100644 --- a/src/core/CCList.ml +++ b/src/core/CCList.ml @@ -404,6 +404,8 @@ let rec equal f l1 l2 = | [], _ | _, [] -> false | x1 :: l1', x2 :: l2' -> f x1 x2 && equal f l1' l2' +[@@@iflt 5.1] + let rec flat_map_kont f l kont = match l with | [] -> kont [] @@ -415,8 +417,6 @@ let rec flat_map_kont f l kont = let kont' tail = kont (append x tail) in flat_map_kont f l' kont' -[@@@iflt 4.14] - let[@inline] flat_map f l = match l with | [] -> [] diff --git a/tests/core/t_list.ml b/tests/core/t_list.ml index 8cee6945..c195436a 100644 --- a/tests/core/t_list.ml +++ b/tests/core/t_list.ml @@ -216,8 +216,12 @@ t @@ fun () -> flat_map (fun x -> [ x + 1; x * 2 ]) [ 10; 100 ] = [ 11; 20; 101; 200 ] ;; + t @@ fun () -> List.length (flat_map (fun x -> [ x ]) (1 -- 300_000)) = 300_000 ;; +t @@ fun () -> +List.length (flat_map (fun _ -> 1 -- 300_000) (1 -- 2)) = 600_000 +;; eq [ 1; 2; 2; 3; 3; 3 ] (flat_map_i (fun i x -> replicate (i + 1) x) [ 1; 2; 3 ])