Version française
Home     About     Download     Resources     Contact us    
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:
> 
> On Fri, Jul 13, 2001 at 09:40:11PM -0700, Alexander V. Voinov wrote:
> 
> > And in general, the inability to pass free variables to be bound later
> > limits the tail recursion optimization. And forces to use iterations
> > when they exist (as they do in OCaml).
> 
> ??????? I don't understand. Can you give an example?

Sorry :-), an example in Prolog is:

f([],[]) :- !.
f([H1|T1], [H2|T2]) :-
	g(H1,H2),
	f(T1,T2).

Last call in this case deals with the final locations of the tails of
the lists. Though chains of indirection may be long, they are handled by
the garbage collection, whose launch strategy may be based more on
heuristics than on a theory. In OCaml, if it were possible to handle the
special case of the _two_ last calls of the form:

    h::(make_tail arg1 argN),

that is
	CALL make_tail
	CONS

and change them to
 
	PREPARE_CONS
	CALL make_tail

the scope of tail recursion optimization would increase. But it's
unlikely that this idea didn't come to developers. Which may mean that
this [being not that simple] is impossible.

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