Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] generic programming
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2002-07-04 (02:02)
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".

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 

j h woodyatt <>

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: