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 FAA23723; Fri, 19 Jul 2002 05:58:12 +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 FAA23719 for ; Fri, 19 Jul 2002 05:58:11 +0200 (MET DST) Received: from dewberry.cc.columbia.edu (dewberry.cc.columbia.edu [128.59.59.68]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g6J3wA124630 for ; Fri, 19 Jul 2002 05:58:11 +0200 (MET DST) Received: from there (tw304h3.cpmc.columbia.edu [156.111.84.180]) by dewberry.cc.columbia.edu (8.9.3/8.9.3) with SMTP id XAA11620; Thu, 18 Jul 2002 23:58:09 -0400 (EDT) Message-Id: <200207190358.XAA11620@dewberry.cc.columbia.edu> Content-Type: text/plain; charset="iso-8859-1" From: Oleg To: William Lovas , caml-list Subject: Re: [Caml-list] productivity improvement Date: Thu, 18 Jul 2002 23:59:11 -0400 X-Mailer: KMail [version 1.3.2] References: <20020716172916.4903.qmail@web10702.mail.yahoo.com> <200207182313.TAA19905@dewberry.cc.columbia.edu> <20020718235405.GA22176@force.stwing.upenn.edu> In-Reply-To: <20020718235405.GA22176@force.stwing.upenn.edu> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Thursday 18 July 2002 07:54 pm, William Lovas wrote: > 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. [...] Not really. Run-time type identification (RTTI) and a "switch" statement should work in a free (non-member) function just like O'Caml's "match" AFAIK. Regards, Oleg ------------------- 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