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 QAA23322; Sun, 26 Sep 2004 16:36:31 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id QAA21727 for ; Sun, 26 Sep 2004 16:36:29 +0200 (MET DST) Received: from smtp3.adl2.internode.on.net (smtp3.adl2.internode.on.net [203.16.214.203]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id i8QEaQLg011931 for ; Sun, 26 Sep 2004 16:36:28 +0200 Received: from [192.168.1.200] (ppp202-133.lns1.syd3.internode.on.net [203.122.202.133]) by smtp3.adl2.internode.on.net (8.12.9/8.12.9) with ESMTP id i8QEaJOU015541; Mon, 27 Sep 2004 00:06:21 +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: Jon Harrop Cc: caml-list In-Reply-To: <200409261405.37558.jon@jdh30.plus.com> References: <20040925225246.48566.qmail@web53010.mail.yahoo.com> <200409260234.50929.jon@jdh30.plus.com> <7f8e92aa04092522313d47820d@mail.gmail.com> <200409261405.37558.jon@jdh30.plus.com> Content-Type: text/plain Message-Id: <1096209379.28613.64.camel@pelican.wigram> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.2 (1.2.2-4) Date: 27 Sep 2004 00:36:19 +1000 Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 4156D3EA.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 hofs:01 covariance:01 monomorphic:01 generative:01 inference:01 lacking:01 9660:01 glebe:01 compiler:01 ocaml:01 ocaml:01 garbage:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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 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