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: | 2004-09-26 (20:14) |
From: | Radu Grigore <radugrigore@g...> |
Subject: | Re: [Caml-list] C++ STL and template features compared with OCaml parametric polymorphism and OO features |
On Sun, 26 Sep 2004 19:51:52 +0100, Jon Harrop <jon@jdh30.plus.com> wrote: > > Nope. That only works for a limited class algorithms. > > Try a map function.. woops, you can't type it .. :) > Yes you can: > # let vec_add map2 = map2 ( +. );; > val vec_add : ((float -> float -> float) -> 'a) -> 'a = <fun> > > So you can then do: > > # let list_add = vec_add List.map2;; > val list_add : float list -> float list -> float list = <fun> > > I think you're thinking of a function to convert between 'a and 'b container > types. I think the idea is that you can't write a _generic_ map. All you did above is a dipatcher that gives the job to a specialized map function: List.map2. The accumulate function in C++ is not a simple dispatcher. It can implement the logic of "fold" because there is an extra level of abstraction: iterators. But what John says is possible in FISh (namely, writing a generic, shape preserving map) sounds quite cool. regards, radu "Get your data structures correct first and the rest of the program will write itself." – David Jones. 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