Browse thread
[Caml-list] generic programming
-
Oleg
- Johan Baltié
-
Ketanu
-
Chris Hecker
- Oleg
-
Peter Wood
- james woodyatt
- John Max Skaller
- Francois Pottier
-
Chris Hecker
- Jun P.FURUSE
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | james woodyatt <jhw@w...> |
| Subject: | Re: [Caml-list] Re: generic programming |
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 <jhw@wetware.com> ------------------- 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