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] generic programming
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2002-07-08 (09:54)
From: Francois Pottier <francois.pottier@i...>
Subject: Re: [Caml-list] Re: generic programming
On Sat, Jul 06, 2002 at 12:05:30AM +0100, Dave Berry wrote:
> >An iterator is a function that returns a function which maintains a
> >piece of internal state. 
> But can you compile it down to a single increment instruction on a pointer
> (for an iterator over an array)?

*In principle*, a compiler could perform closure analysis and determine
that the code pointer for the function `next' is known, so the closure
for `next' could be represented (in the case of an array iterator) as
a block containing a pointer to the array and a pointer to a reference
cell containing the current index. The code for the function could be
inlined and would consist in fetching both pieces of information, reading
the array and updating the reference cell.

*In principle*, a compiler could perform escape analysis and allocate the
reference cell on the stack, so accessing and updating it would be cheaper.

*In principle*, a compiler could perform must-alias analysis and find out
that the address of the array is already available elsewhere, thus obviating
the need to create a closure entirely.

Some ML compilers perform some of these optimizations. O'Caml performs none,
as far as I know; they are tricky to implement, especially in combination.
I'd be curious to see how C++ achieves this.

> Also, can you compare two iterators for equality?

What is the semantics of such a comparison?

François Pottier
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners