mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
fix: overshoot, concat_map is only TRMC after 5.1
This commit is contained in:
parent
9ebfbe1c2d
commit
8dc4d5a706
2 changed files with 6 additions and 2 deletions
|
|
@ -404,6 +404,8 @@ let rec equal f l1 l2 =
|
||||||
| [], _ | _, [] -> false
|
| [], _ | _, [] -> false
|
||||||
| x1 :: l1', x2 :: l2' -> f x1 x2 && equal f l1' l2'
|
| x1 :: l1', x2 :: l2' -> f x1 x2 && equal f l1' l2'
|
||||||
|
|
||||||
|
[@@@iflt 5.1]
|
||||||
|
|
||||||
let rec flat_map_kont f l kont =
|
let rec flat_map_kont f l kont =
|
||||||
match l with
|
match l with
|
||||||
| [] -> kont []
|
| [] -> kont []
|
||||||
|
|
@ -415,8 +417,6 @@ let rec flat_map_kont f l kont =
|
||||||
let kont' tail = kont (append x tail) in
|
let kont' tail = kont (append x tail) in
|
||||||
flat_map_kont f l' kont'
|
flat_map_kont f l' kont'
|
||||||
|
|
||||||
[@@@iflt 4.14]
|
|
||||||
|
|
||||||
let[@inline] flat_map f l =
|
let[@inline] flat_map f l =
|
||||||
match l with
|
match l with
|
||||||
| [] -> []
|
| [] -> []
|
||||||
|
|
|
||||||
|
|
@ -216,8 +216,12 @@ t @@ fun () ->
|
||||||
flat_map (fun x -> [ x + 1; x * 2 ]) [ 10; 100 ] = [ 11; 20; 101; 200 ]
|
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 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 ]
|
eq [ 1; 2; 2; 3; 3; 3 ]
|
||||||
(flat_map_i (fun i x -> replicate (i + 1) x) [ 1; 2; 3 ])
|
(flat_map_i (fun i x -> replicate (i + 1) x) [ 1; 2; 3 ])
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue