fix: overshoot, concat_map is only TRMC after 5.1

This commit is contained in:
Simon Cruanes 2023-12-20 14:36:35 -05:00
parent 9ebfbe1c2d
commit 8dc4d5a706
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
2 changed files with 6 additions and 2 deletions

View file

@ -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
| [] -> []

View file

@ -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 ])