(* Create a stream of 45 million elements. *) let size = 45000000 in let next n = if n < size then (Some ((), n + 1)) else None in let a_large_stream = MyStream.unfold next 0 in (* Force its construction in memory. *) let the_last_one = MyStream.last a_large_stream in (* Memory space monitoring provided by the garbage collector. *) let () = Printf.printf "Maximum size of the major heap, in words = %i\n" (Gc.stat ()).Gc.top_heap_words in let () = Printf.printf "Number of heap compactions since the program was started = %i\n" (Gc.stat ()).Gc.compactions in (* Wait for the key [Enter] to be pressed. *) let () = print_string "Press [Enter] to quit." in let _ = read_line () in (* let a_large_stream = MyStream.unfold next 0 in *) (* Return the last element and (the address of) this stream. *) (the_last_one, a_large_stream)