Browse thread
[Caml-list] C++ STL and template features compared with OCaml parametric polymorphism and OO features
[
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: | Brian Hurt <bhurt@s...> |
| Subject: | Re: [Caml-list] C++ STL and template features compared with OCaml parametric polymorphism and OO features |
On Mon, 27 Sep 2004, Jon Harrop wrote:
> I think we are, because I think iterators are only really useful in an
> imperative setting. Hence C++ programmers use them extensively but OCaml
> programmers do not. Folds are simply not feasible in C++. I'm sure Stepanov
> would have reinvented them if they had been... ;-)
Two comments:
First, iterators are usefull in a functional setting, for two reasons.
The first is they allow lazy application of transformations. It's easy to
define a map on an interator to do the transforms as the values get pulled
out. And second, they provide a generic way to plug data structures
together. All you need to write is a to_iterator and from_iterator for
each data structure, and then all data structures can talk to each other.
Second, you can do fold, map, iter, etc. in C++- it's just a pain. To
emulate HOFs you define a new class with single virtual member function.
The virtual member function then becomes your HOF. Of course, 1 line of
Ocaml code has just become a dozen lines of C++, but that doesn't mean it
can't be done...
--
"Usenet is like a herd of performing elephants with diarrhea -- massive,
difficult to redirect, awe-inspiring, entertaining, and a source of
mind-boggling amounts of excrement when you least expect it."
- Gene Spafford
Brian
-------------------
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