fix insidious bug in CCList.flat_map

we have been accidentally relying on evaluation order.
This commit is contained in:
Simon Cruanes 2023-12-15 22:36:39 -05:00
parent 7436727942
commit c4dcf1efe2
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4

View file

@ -372,16 +372,20 @@ let[@inline] flat_map f l =
match l with match l with
| [] -> [] | [] -> []
| [ x ] -> f x | [ x ] -> f x
| x :: tl -> flat_map_kont f l Fun.id | _ :: _ -> flat_map_kont f l Fun.id
[@@@else_] [@@@else_]
(* let flat_map = concat_map *)
let flat_map f l = let flat_map f l =
let rec direct i f l = let rec direct i f l =
match l with match l with
| [] -> [] | [] -> []
| [ x ] -> f x | [ x ] -> f x
| [ x; y ] -> append (f x) (f y) | [ x; y ] ->
let x = f x in
let y = f y in
append x y
| _ when i = 0 -> flat_map_kont f l Fun.id | _ when i = 0 -> flat_map_kont f l Fun.id
| x :: y :: tl -> | x :: y :: tl ->
let x = f x in let x = f x in