From ec0e92da35aeb36f50eaf9d35f8e4a47e0ae48cb Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Thu, 1 Oct 2015 18:53:39 +0200 Subject: [PATCH] bugfix in `CCKList.take`, it was slightly too eager --- src/iter/CCKList.ml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/iter/CCKList.ml b/src/iter/CCKList.ml index 6adf9d1d..4a55e967 100644 --- a/src/iter/CCKList.ml +++ b/src/iter/CCKList.ml @@ -101,10 +101,11 @@ let iteri f l = let length l = fold (fun acc _ -> acc+1) 0 l -let rec take n (l:'a t) () = match l () with - | _ when n=0 -> `Nil - | `Nil -> `Nil - | `Cons (x,l') -> `Cons (x, take (n-1) l') +let rec take n (l:'a t) () = + if n=0 then `Nil + else match l () with + | `Nil -> `Nil + | `Cons (x,l') -> `Cons (x, take (n-1) l') let rec take_while p l () = match l () with | `Nil -> `Nil