This commit is contained in:
Simon Cruanes 2023-12-05 12:19:15 -05:00
parent 7fcf26963b
commit 36790cf3ed
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
2 changed files with 5 additions and 4 deletions

View file

@ -313,7 +313,7 @@ let rec unfold_kont f seed k =
match f seed with match f seed with
| None -> k [] | None -> k []
| Some (v, next) -> | Some (v, next) ->
let k' tl = v :: tl in let k' tl = v :: k tl in
unfold_kont f next k' unfold_kont f next k'
let[@inline] unfold f seed = let[@inline] unfold f seed =

View file

@ -131,17 +131,18 @@ q
= (List.rev l, flat_map (fun x -> [ x; x + 10 ]) l)) = (List.rev l, flat_map (fun x -> [ x; x + 10 ]) l))
;; ;;
t @@ fun () -> eq ~printer:Q.Print.(list int) ~name:"unfold1" [ 0; 2; 4; 6; 8; 10 ]
@@
let f x = let f x =
if x <= 5 then if x <= 5 then
Some (2 * x, x + 1) Some (2 * x, x + 1)
else else
None None
in in
unfold f 0 = [ 0; 2; 4; 6; 8; 10 ] unfold f 0
;; ;;
t @@ fun () -> t ~name:"unfold2" @@ fun () ->
let l = let l =
unfold unfold
(fun n -> (fun n ->