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] C++ STL and template features compared with OCaml parametric polymorphism and OO features
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-09-27 (10:50)
From: Radu Grigore <radugrigore@g...>
Subject: Re: [Caml-list] C++ STL and template features compared with OCaml parametric polymorphism and OO features
On Mon, 27 Sep 2004 02:59:43 +0100, Jon Harrop <> wrote:

> What is the difference between a generic function and a function which
> dispatches to appropriate specialised functions?

For the client of the function there is no difference.

For the writter of the function there is a big difference, especially
if it has to write the specialized versions. The good news is that the
OCaml library gives you those specialized functions (fold) for common
data structures like List and Array. The bad news is that you are on
your own if you define new data structures that can be viewed as

The meaning of "fold" is "apply this function repeatedly for each
element of the data-structure and accumulate the result". I'd like to
be able to write this in code _once_ for every data-structure that can
be seen as a sequence (i.e. a set of totaly ordered elements). You can
do this with iterators. As the article cited by Vasili shows there is
an analogue of iterators in functional languages. Another solution is
implemented in Extlib. So we are not really talking here about
differences between OCaml and C++; we are talking about library

However, John said that talking about "sequences" means that we are
actually artificially limiting a more general concept: shape. But I
don't quite understand this idea fully.


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