Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Generation of streams is slow
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ 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.

Bug reports:  FAQ:
To unsubscribe, mail  Archives: