diff --git a/sequence.ml b/sequence.ml index befc55b..c4cd668 100644 --- a/sequence.ml +++ b/sequence.ml @@ -69,7 +69,9 @@ let drop n seq = (** Reverse the sequence. O(n) memory. *) let rev seq = let seq_fun k = - (* continuation for the prefix of the input sequence so far *) + (* if we have traversed [s_1, ..., s_m], [cont ()] will call [k] on s_m, + s_{m-1}, ..., s_1. Once we know [s_{m+1}], we update [cont] so that it + first returns it, and then called the previous cont. *) let cont = ref (fun () -> ()) in iter (fun x -> let current_cont = !cont in diff --git a/tests.ml b/tests.ml index adae105..36641d1 100644 --- a/tests.ml +++ b/tests.ml @@ -22,7 +22,7 @@ let _ = (Sequence.map (fun (x, y) -> (string_of_int x) ^ " -> " ^ (string_of_int y)) (Sequence.Hashtbl.to_seq h)) in - let l3 = Sequence.List.of_seq (Sequence.Int.range ~start:0 ~stop:42) in + let l3 = Sequence.List.of_seq (Sequence.rev (Sequence.Int.range ~start:0 ~stop:42)) in Format.printf "l=@[[%a]@]@." (pp_list Format.pp_print_int) l; Format.printf "l'=@[[%a]@]@." (pp_list Format.pp_print_int) l'; Format.printf "l''=@[[%a]@]@." (pp_list Format.pp_print_int) l'';