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 EAA22255; Thu, 4 Jul 2002 04:02:06 +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 EAA21926 for ; Thu, 4 Jul 2002 04:02:04 +0200 (MET DST) Received: from wetware.wetware.com (wetware.wetware.com [199.108.16.1]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g64223920245 for ; Thu, 4 Jul 2002 04:02:03 +0200 (MET DST) Received: from (local broken client) localhost(dh02.wetware.com[199.108.16.42]) (2766 bytes) by wetware.wetware.com via sendmail with P:esmtp/R:bind_hosts/T:inet_zone_bind_smtp (sender: ) id for ; Wed, 3 Jul 2002 19:02:02 -0700 (PDT) (Smail-3.2.0.114 2001-Aug-6 #1 built 2002-Jan-4) Date: Wed, 3 Jul 2002 19:02:07 -0700 Subject: Re: [Caml-list] Re: generic programming Content-Type: text/plain; charset=US-ASCII; format=flowed Mime-Version: 1.0 (Apple Message framework v482) Cc: caml-list@inria.fr To: Peter Wood From: james woodyatt In-Reply-To: <20020703215519.GA9429@localhost.localdomain> Message-Id: <0B020612-8EF2-11D6-95EA-000502DB38F5@wetware.com> Content-Transfer-Encoding: 7bit X-Mailer: Apple Mail (2.482) Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Wednesday, July 3, 2002, at 02:55 PM, Peter Wood wrote: > > Here's an interesting (though old) article by Henry Baker, "Iterators: > Signs of Weakness in Object-Oriented Languages". > > http://linux.rice.edu/~rahul/hbaker/Iterator.html Funny you should bring that up now. I've been working on basically the same problem in recent days. The approach I've been taking seems to me to be similar to what Baker describes in that paper. I have a functional red-black binary tree functor that defines a pair of functions for creating generic functional streams of the objects in a tree (one in increasing order and the other in decreasing order). I've written functions that map red-black trees (and other specialized collections) into objects of a functional stream class. I've also written a library of functions that perform some generic algorithms on the contents of generic functional streams (and pairs of streams), e.g. fold, compare, etc. It's true that the stream of elements in my red-black tree implementation requires a stack of previously visited parent nodes, but that's an artifact of my implementation of the red-black tree algorithm. (If I had used the traditional mutable red-black tree algorithm, I could have avoided the stack in the stream object.) So... I've also written "more efficient" variants that use the program stack when there's only one tree in the loop, though-- I've not yet measured the improvement. I think the whole thing makes "rather tasteful use of objects and class types" to borrow a phrase from Dr. Leroy. Let me poke at it some more, then I'll document it and throw it up for review. You'll be able to judge for yourself. Meanwhile, I'd say "generic programming" is quite "well-enabled" by Ocaml. Whether you want to do it in the style of Stepanov's STL is a whole other question... Personally, I'd rather be flensed alive by a gang of Welsh football hooligans armed with potato peelers than write another line of C++ using the STL. (Okay, that's unnecessarily inflammatory.) -- j h woodyatt ------------------- 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