English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[Caml-list] [ANN] The Missing Library
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-04-28 (12:38)
From: Nicolas Cannasse <warplayer@f...>
Subject: Re: [Caml-list] [ANN] The Missing Library
> > Why can't you do this kind of in ocaml?  Returning something like a
> > "next" function would seem to give you a very basic (but usable)
> > iterator.  Which part of the iterator abstraction can't you do?
> I suggest you try it. I don't know how to answer the question.
> I think the answer is 'C++ templates provide functorial
> polymorphism (polyadicity), Ocaml has no such expressive power.'
> HOF's like 'map' and 'fold' make sense
> for polynomial data structures -- lists and trees etc.
> But you have to write 'List.map' or 'Array.map'. There
> is no single 'map' which works for all data structures
> in Ocaml.

There is ExtLib Enum.map that's pretty good at doing that.

> There is in C++, and its a one line idiom:
> // STL copy
> for(; i!=e; ++i) *o++ = *i++;
> Fold is as easy to define (called Accumulate in STL).
> These definitions are polyadic. They work for ALL
> data structures -- provided they have iterators
> of course :D

That's exactly the same as ExtLib enums : define an enumerator for your data
structure, and you can apply a full range of algorithms on it. I don't
really understand the difference with  STL.

Nicolas Cannasse

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