From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id LAA00177; Mon, 8 Jul 2002 11:54:55 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id LAA00140 for ; Mon, 8 Jul 2002 11:54:54 +0200 (MET DST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g689ssv12530 for ; Mon, 8 Jul 2002 11:54:54 +0200 (MET DST) Received: (from fpottier@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id LAA32735 for caml-list@inria.fr; Mon, 8 Jul 2002 11:54:53 +0200 (MET DST) Date: Mon, 8 Jul 2002 11:54:53 +0200 From: Francois Pottier To: caml-list@inria.fr Subject: Re: [Caml-list] Re: generic programming Message-ID: <20020708115453.A32472@pauillac.inria.fr> Reply-To: Francois.Pottier@inria.fr References: <4.3.2.7.2.20020703102610.0248b280@mail.d6.com> <200207030246.WAA28665@dewberry.cc.columbia.edu> <87r8il436y.fsf@ketanu.dyndns.org> <4.3.2.7.2.20020703102610.0248b280@mail.d6.com> <20020705103323.A14853@pauillac.inria.fr> <4.1.20020706000345.009f9610@pop3.btclick.com> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Mailer: Mutt 1.0i In-Reply-To: <4.1.20020706000345.009f9610@pop3.btclick.com>; from daveb@tardis.ed.ac.uk on Sat, Jul 06, 2002 at 12:05:30AM +0100 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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 Francois.Pottier@inria.fr http://pauillac.inria.fr/~fpottier/ ------------------- 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