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: skaller <skaller@u...>
Subject: Re: [Caml-list] C++ STL and template features compared with OCaml parametric polymorphism and OO features
On Sun, 2004-09-26 at 15:31, 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++ :)

C++ STL + templates offer a messy and unreliable form
of polyadic programming not available in Ocaml.

C++ cheats quite a bit. 

So does Extlib. Basically, if you provide some
function such as 'get_next()' you can convert
some data structure to a fixed stream type, and then 
you can fold it with one algorithm. However, of course this 
isn't enough to provide map (since the original 
data structure is lost).

C++ has the same problem -- you can certainly
build a data structure of mapped values with
both systems, but that isn't a map:

	map: 'a F * ('a -> 'b) -> 'b F

is a map, where F is some type functor such as list,
bintree, array, etc. IE map should preserve the shape.

FISh can do that -- a single definition of 'map'
implements he above formula for all data types F.

I guess:

value variables .. type variables .. functor variables

Languages like Java are stuck in stage 1 and should
no longer be entitled to be considered 'high level
programming languages'. C++ and Ocaml are 
stuck in stage 2. For more reusability we must
proceed to stage 3.

In some way dynamic typing allows polyadic programming,
but I guess we'd like to get it without losing the
benefits of static typing.

-- 
John Skaller, mailto:skaller@users.sf.net
voice: 061-2-9660-0850, 
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language http://felix.sf.net



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