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: sejourne_kevin <sejourne_kevin@y...>
Subject: Re: [Caml-list] C++ STL and template features compared with OCaml parametric polymorphism and OO features
Radu Grigore wrote:
> On Sun, 26 Sep 2004 02:34:50 +0100, Jon Harrop <jon@jdh30.plus.com> wrote:
> 
>>For example, to sum the floating-point elements of a container in C++, one
>>might write:
> 
> 
> This example is slightly unfair to C++. In the OCaml code:
> 
> 
>>let sum fold_left c = fold_left ( +. ) 0. c
>>sum List.fold_left [0.; 1.; 2.; 3.; 4.]
>>sum Array.fold_left [|0.; 1.; 2.; 3.; 4.|]
> 
> 
> ...you use _two_ library functions (namely List.fold_left and
> Array.fold_left). Surely you should at least use one for C++ :)
not two library, but _three_ if you count module Pervasives :)


> regards,
>  radu
> PS: ok, maybe it's unfair to ocaml now that I used macros..
No it's totaly fair. There is a 'cpp' preprocessor for ocaml.

#define P(x) (fst x) (snd x) (fst x)
#define S(x) (snd x)
let x = ("world","hello");;
Printf.printf "%s %s %s %s\n" S(x) P(x);;

ocamlc -pp /lib/cpp test.ml

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