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: | Alexander V. Voinov <avv@q...> |
| Subject: | Re: [Caml-list] Generation of streams is slow |
Hi Daniel, Daniel de Rauglaudre 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) I see, Prolog habits are hard to leave. But this solution doesn't look as "natural" as mine, and requires additional time to reverse the result. I try to acquire hints for the everyday use, of lists and other abstract sequences in this case. Not just a particular problem to solve. Alexander ------------------- 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