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 PAA22085; Fri, 5 Jul 2002 15:54:38 +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 PAA22438 for ; Fri, 5 Jul 2002 15:54:38 +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 g65Ds6f27374; Fri, 5 Jul 2002 15:54:06 +0200 (MET DST) Received: (from xleroy@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id PAA22340; Fri, 5 Jul 2002 15:54:05 +0200 (MET DST) Date: Fri, 5 Jul 2002 15:54:05 +0200 From: Xavier Leroy To: Chris Hecker Cc: Francois Pottier , caml-list@inria.fr Subject: Re: [Caml-list] Re: generic programming Message-ID: <20020705155405.A20462@pauillac.inria.fr> References: <20020705104249.B14853@pauillac.inria.fr> <200207030246.WAA28665@dewberry.cc.columbia.edu> <4.3.2.7.2.20020703102610.0248b280@mail.d6.com> <3D246739.4030204@ozemail.com.au> <20020705104249.B14853@pauillac.inria.fr> <20020705112551.B16273@pauillac.inria.fr> <4.3.2.7.2.20020705024112.038909f0@mail.d6.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.3.2.7.2.20020705024112.038909f0@mail.d6.com>; from checker@d6.com on Fri, Jul 05, 2002 at 02:57:57AM -0700 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > [Lots of interesting points about "push" vs. "pull" APIs omitted] All you said is very reasonable, but I think you're generalizing the discussion (especially with the GUI examples) beyond what I had in mind, i.e. iteration over in-memory data structures. In particular: > Giving up explicit control over the flow of your program is a > serious problem in my opinion When the task at hand is sufficiently abstract, e.g. "visit every element of this set once", or "transform this list by applying this function to each element", explicit control over the flow is something that I'll gladly omit. (Just like I'm happy not to have explicit control over memory deallocation.) In other terms, are you really saying that you prefer writing for (Enumeration e = l.elements(); e.hasMoreElements(); ) frobnicate((SomeClass) e.nextElement()); over writing List.iter frobnicate l > It seems like it's something a good language should support well. > [...] > I wish Ocaml supported imperative/pull coding styles better, which > is why I'm interested in this thread. The language provides full imperative power, and it's easy to write imperative iterators over concrete data structure (like François showed). So, what more would you like? True, abstract types provided by the standard library do not provide imperative iterators (heavens forbid :-); but there are about three of them (Set, Map, and Hashtbl), so I don't think this would really stop you, should you embark in writing STL-style or java.util-style code in OCaml... > Furthermore, it seems like it's a common trap to fall into saying the > familiar "you don't want to do that" (like your comment about hashtables) My comment is more along the need of "I don't see when you'd ever need to do that, but please enlighten me". Say you have two hashtables; please show me a situation where iterating in parallel over the two hashtables (using two imperative iterators) would be more convenient than what you can write with OCaml's current hashtable interface (only functional iterators). - Xavier Leroy ------------------- 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