Browse thread
[Caml-list] Generation of streams is slow
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Daniel de Rauglaudre <daniel.de_rauglaudre@i...> |
| Subject: | Re: [Caml-list] Generation of streams is slow |
Hi,
On Fri, Jul 13, 2001 at 07:51:09PM -0700, Alexander V. Voinov wrote:
> Yes, the difference is substantial, but it gets longer and longer anyway
> with more elements parsed (for a slightly more complex program, which
> parses the stream as it is generated) and crashes at some point.
I did not test, but looking at your code, I see that neither parse_stream
nor parse_stream' is tail recursive! It is not a question of parsers, now:
your recurive calls are never the last action.
Perhaps this version would work (not tested):
let rec parse_stream list s =
match s with parser
[< 'i; s' >] -> begin
if i mod 1000 = 0 then begin
printf "picked element %d\n" i;
flush stdout
end;
parse_stream (i :: list) s'
end
| [< >] -> (printf "end\n"; flush stdout; List.rev list)
let _ =
print_list (parse_stream' [] (gen_stream 700000))
--
Daniel de RAUGLAUDRE
daniel.de_rauglaudre@inria.fr
http://cristal.inria.fr/~ddr/
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr