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 BAA20783; Fri, 19 Jul 2002 01:54:10 +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 BAA20779 for ; Fri, 19 Jul 2002 01:54:09 +0200 (MET DST) Received: from nexus.stwing.upenn.edu (NEXUS.STWING.UPENN.EDU [165.123.132.61]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g6INs8T17655 for ; Fri, 19 Jul 2002 01:54:08 +0200 (MET DST) Received: from force.stwing.upenn.edu (daemon@force.stwing.upenn.edu [165.123.132.65]) by nexus.stwing.upenn.edu (8.11.6/8.11.6) with ESMTP id g6INs6T14598 (using TLSv1/SSLv3 with cipher EDH-RSA-DES-CBC3-SHA (168 bits) verified NO) for ; Thu, 18 Jul 2002 19:54:07 -0400 (EDT) Received: (from wlovas@localhost) by force.stwing.upenn.edu (8.11.6/8.11.6) id g6INs6122571 for caml-list@inria.fr; Thu, 18 Jul 2002 19:54:06 -0400 (EDT) Date: Thu, 18 Jul 2002 19:54:05 -0400 From: William Lovas To: caml-list Subject: Re: [Caml-list] productivity improvement Message-ID: <20020718235405.GA22176@force.stwing.upenn.edu> Mail-Followup-To: caml-list References: <20020716172916.4903.qmail@web10702.mail.yahoo.com> <200207182313.TAA19905@dewberry.cc.columbia.edu> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200207182313.TAA19905@dewberry.cc.columbia.edu> User-Agent: Mutt/1.3.25i Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Thu, Jul 18, 2002 at 07:14:06PM -0400, Oleg wrote: > However, the C++ version looks more "extensible" to me: Suppose that in a > while, you decide that you want your "node" to be not only Leaf or Unop or > Binop, but also Triop: > > type 'a node = Leaf of 'a | Unop of ('a->'a) * 'a node | Binop of ('a * 'a -> > 'a) * 'a node * 'a node | Triop of ('a * 'a * 'a -> 'a) * 'a node * 'a node * > 'a node;; > > You will need to modify the original node type and function "eval" by adding > an extra pattern to "match" statement, and then recompile everying that > depends on it. At the same time, with C++ the type of node remains the same. > You just need to derive a new class from it: > > [snip] > > Recompiling isn't necessary. In fact, "old code" may call "new code" if you > happen to pass it a node that happens to be a triop. Yes, but what if you decide to add a new function on nodes? Like say, typecheck, or eval2, with slightly different semantics? In the O'Caml version, it's as simple as that -- add a new function and run with it. With the C++ version, though, now you have to modify *every* *single* *class* that inherits from node, and recompile them all. So it really seems that it's just a question of what's most important for your own particular purpose. Someone looking to extend the definition of node indefinitely would prefer an object-oriented version, while someone focused on providing new functionality over nodes would prefer the functional version. > Oleg > > P.S. Having read the CalTech tutorial and chapters 1-4 & 14 of the O'Reilly > book, and having gotten some experience with O'Caml, I'm running low on > motivation right now. Please give me examples of what's > hard/awkward/impossible in C++, but relatively easy in O'Caml, if any (I have > only finite time, so 50 KLOC Coq is not a good example :) It strikes me that although you were able to quite easily translate this toy evaluator example into C++, this may not have been the case with a larger, more complex example. It's something that scales exponentially, so you're probably not going to find very many small, concise examples that show conclusively how much easier O'Caml is. (And, of course, you have to take into account the style question mentioned above. One style does not necessarily fit all.) William ------------------- 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