From c4dcf1efe2458d15ca76a284401fce9d48cc809e Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Fri, 15 Dec 2023 22:36:39 -0500 Subject: [PATCH] fix insidious bug in CCList.flat_map we have been accidentally relying on evaluation order. --- src/core/CCList.ml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/core/CCList.ml b/src/core/CCList.ml index 7d466a66..2132b313 100644 --- a/src/core/CCList.ml +++ b/src/core/CCList.ml @@ -372,16 +372,20 @@ let[@inline] flat_map f l = match l with | [] -> [] | [ x ] -> f x - | x :: tl -> flat_map_kont f l Fun.id + | _ :: _ -> flat_map_kont f l Fun.id [@@@else_] +(* let flat_map = concat_map *) let flat_map f l = let rec direct i f l = match l with | [] -> [] | [ 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 | x :: y :: tl -> let x = f x in