Skip to content

Commit

Permalink
fix: overshoot, concat_map is only TRMC after 5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
c-cube committed Dec 20, 2023
1 parent 9ebfbe1 commit 8dc4d5a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/core/CCList.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 []
Expand All @@ -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
| [] -> []
Expand Down
4 changes: 4 additions & 0 deletions tests/core/t_list.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ])
Expand Down

0 comments on commit 8dc4d5a

Please sign in to comment.