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 PAA07316; Wed, 28 Apr 2004 15:29:27 +0200 (MET DST) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id PAA08268 for ; Wed, 28 Apr 2004 15:29:26 +0200 (MET DST) Received: from eris.rz.uni-saarland.de (eris.rz.uni-saarland.de [134.96.7.8]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i3SDTPjq011686 for ; Wed, 28 Apr 2004 15:29:25 +0200 Received: from cs.uni-sb.de (cs.uni-sb.de [134.96.254.254]) by eris.rz.uni-saarland.de (8.12.10/8.12.10) with ESMTP id i3SDTOOx31471331 for ; Wed, 28 Apr 2004 15:29:24 +0200 (CST) Received: from mail.cs.uni-sb.de (mail.cs.uni-sb.de [134.96.254.200]) by cs.uni-sb.de (8.12.11/2003091100) with ESMTP id i3SDTNIi019378 for ; Wed, 28 Apr 2004 15:29:23 +0200 (CEST) Received: from ps.uni-sb.de (grizzly.ps.uni-sb.de [134.96.186.68]) by mail.cs.uni-sb.de (8.12.11/2004041400) with ESMTP id i3SDTMQA016840 for ; Wed, 28 Apr 2004 15:29:22 +0200 (CEST) X-Authentication-Warning: email: Host grizzly.ps.uni-sb.de [134.96.186.68] claimed to be ps.uni-sb.de Received: from ps.uni-sb.de (groove.ps.uni-sb.de [134.96.186.172]) by ps.uni-sb.de (8.12.10/8.12.10) with ESMTP id i3SDTJdQ030118; Wed, 28 Apr 2004 15:29:20 +0200 Message-ID: <408FB1AF.3000302@ps.uni-sb.de> Date: Wed, 28 Apr 2004 15:29:19 +0200 From: Andreas Rossberg User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4.1) Gecko/20031114 X-Accept-Language: en-us, en MIME-Version: 1.0 To: caml-list@inria.fr Subject: Re: [Caml-list] [ANN] The Missing Library References: <1083140676.9537.831.camel@pelican.wigram> <1083151902.29774.18.camel@localhost.localdomain> <1083154175.9537.944.camel@pelican.wigram> In-Reply-To: <1083154175.9537.944.camel@pelican.wigram> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-AntiVirus: checked by AntiVir Milter 1.0.6; AVE 6.25.0.2; VDF 6.25.0.38 X-Miltered: at nez-perce by Joe's j-chkmail ("http://j-chkmail.ensmp.fr")! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; rossberg:01 rossberg:01 uni-sb:01 caml-list:01 iterator:01 iterator:01 abstraction:01 functorial:01 expressive:01 generic:01 hofs:01 stream':01 stream':01 model:01 uni-sb:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk skaller wrote: >> >>Why can't you do this kind of in ocaml? Returning something like a >>"next" function would seem to give you a very basic (but usable) >>iterator. Which part of the iterator abstraction can't you do? > > I suggest you try it. I don't know how to answer the question. > I think the answer is 'C++ templates provide functorial > polymorphism (polyadicity), Ocaml has no such expressive power.' It has, but only on the module level. Anyway, I don't think it is needed for generic iteration. The most important aspects of iterators easily can be captures by either HOFs or by lazy streams. For example, a forward iterator just might be an arbitrary function of type unit -> 'a option Repeated calls advance the iterator, at the end it returns None. More functionally, with streams, an iterator is a value of type 'a stream, probably definable in OCaml as follows: type 'a stream = 'a stream' lazy_t and 'a stream' = Nil | Cons of 'a * 'a stream Essentially, you iterate over (parts of) arbitrary structure by turning them into lazy lists. Using laziness to move from a push to a pull model (which is what your control inversion means, IIUC) is rather a standard FP technique. The main difference wrt C++ style iterators is that you need to give the end of the iteration in advance (if you want some particular range). I don't think you lose something important by that limitation. - Andreas -- Andreas Rossberg, rossberg@ps.uni-sb.de Let's get rid of those possible thingies! -- TB ------------------- 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