English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

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: 2001-07-14 (04:04)
From: Daniel de Rauglaudre <daniel.de_rauglaudre@i...>
Subject: Re: [Caml-list] Generation of streams is slow

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
	parse_stream (i :: list) s'
    | [< >] -> (printf "end\n"; flush stdout; List.rev list)

  let _ = 
    print_list (parse_stream' [] (gen_stream 700000))

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