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] 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: 2004-09-26 (14:36)
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 23:05, Jon Harrop wrote:
>  If you have HOFs, you 
> just write my "sum" function and get on with something more interesting.

Nope. That only works for a limited class algorithms.
Try a map function.. woops, you can't type it .. :)

This is somehow like the covariance problem: things
kind of work for one variable by cheating, but once
you have several it fails.

> Also, note that the C++ version uses "accumulate" which is effectively 
> equivalent to "folding with addition". In OCaml, you can fold using any 
> function you want, 

Accumulate can accept a function object argument.
C++ DOES have higher order functions. They're just
very clumby to use, but they're just as powerful
as monomorphic Ocaml ones. [My Felix compiler
does all that for you .. write ML, get C++ out]

Ocaml run time can also support polymorphic higher
order functions -- but the type system as of 
Ocaml 3.04 could not. 3.08 can support them with
the same problem as C++: messy housekeeping
is required -- you have to put them in a record
or class. [This is not so good because records 
and variants are generative/nominally typed like C++ classes 
.. Ocaml classes are actually algebraic .. LOL!]

> > Using C++'s <functional> header (or Boost.Lambda for that matter) is
> > sure to give you a headache after programming a bit in a functional
> > language like OCaml. But the same can be said about writting
> > imperative code in OCaml.
> I'd contest that. 

So would I. Ocaml is a much better imperative and OO language
than C++.

> > I have recently compared two implementations of the same small program
> > in C++ and OCaml, both written by me. The OCaml one was 45% the size
> > of the C++ one (byte count). After compression (with bzip2) it was
> > 67%. And it was kind of imperative job so C++ should have been in
> > advantage there. And I know C++ much better than OCaml, so this should
> > have been another advantage..

Sure but Ocaml offers other advantages such as type inference
lacking in C++ that make code more concise -- as well
as nice scoping constructs, lexical scoping, higher
order functions, variants, and garbage collection.
[Did I miss something .. ? :]

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