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-28 (01:21)
From: skaller <skaller@u...>
Subject: Re: [Caml-list] C++ STL and template features compared with OCaml parametric polymorphism and OO features
On Tue, 2004-09-28 at 03:01, Brian Hurt wrote:
> On 28 Sep 2004, skaller wrote:
> > Yes, because it costs nothing, which is much cheaper
> > than the virtual dispatch:
> This is wrong.  It does cost something- it costs code bloat, because now
> instead of a single copy of the comprehension, you have a whole bunch of
> copies, one for each time you call the comprehension. 

I can't demonstrate easily for g++,
but can do so easily for Felix, which uses the same
mechanism. First the input:

include "std";
fun apply[T] (f:T->T,a:T):T => f a;
val x = apply(sin of (double),1.0);
print x; endl;

and here is the code generated by 'flx --inline'

      //x := (Double::sin 1.0);
      ptf->_i1549_v1533_x = (sin((1.0)));
      // primcall Double::print x;
      // primcall Stdout::endl ();
      {std::cout << endl;}

What you claim may be true in general: extensionl
polymorphism costs in terms of code bloat,
and sometimes that leads to a performance cost.
It will be fun to measure that when the Felix optimiser
is working well enough to compare it with ocaml.

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