Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
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 <jon@jdh30.plus.com> 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
sequences.

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
design.

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.

regards,
 radu
http://rgrig.idilis.ro/

-------------------
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