From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id QAA21671; Sun, 26 Sep 2004 16:19:22 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id QAA23449 for ; Sun, 26 Sep 2004 16:19:20 +0200 (MET DST) Received: from smtp1.adl2.internode.on.net (smtp1.adl2.internode.on.net [203.16.214.181]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id i8QEJIr5028668 for ; Sun, 26 Sep 2004 16:19:19 +0200 Received: from [192.168.1.200] (ppp202-133.lns1.syd3.internode.on.net [203.122.202.133]) by smtp1.adl2.internode.on.net (8.12.9/8.12.9) with ESMTP id i8QEJC4Y073848; Sun, 26 Sep 2004 23:49:13 +0930 (CST) Subject: Re: [Caml-list] C++ STL and template features compared with OCaml parametric polymorphism and OO features From: skaller Reply-To: skaller@users.sourceforge.net To: Radu Grigore Cc: caml-list In-Reply-To: <7f8e92aa04092522313d47820d@mail.gmail.com> References: <20040925225246.48566.qmail@web53010.mail.yahoo.com> <200409260234.50929.jon@jdh30.plus.com> <7f8e92aa04092522313d47820d@mail.gmail.com> Content-Type: text/plain Message-Id: <1096208351.28613.46.camel@pelican.wigram> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.2 (1.2.2-4) Date: 27 Sep 2004 00:19:11 +1000 Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce with ID 4156CFE6.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 sourceforge:01 2004:99 2004:99 extlib:01 functor:01 'map':01 functor:01 languages':01 9660:01 glebe:01 implements:01 ocaml:01 ocaml:01 nsw:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Sun, 2004-09-26 at 15:31, Radu Grigore wrote: > On Sun, 26 Sep 2004 02:34:50 +0100, Jon Harrop 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