From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 29655BB91 for ; Sat, 25 Dec 2004 01:26:59 +0100 (CET) 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 iBP0Qv71005677 for ; Sat, 25 Dec 2004 01:26:58 +0100 Received: from [192.168.1.200] (ppp194-89.lns1.syd2.internode.on.net [203.122.194.89]) by smtp1.adl2.internode.on.net (8.12.9/8.12.9) with ESMTP id iBP0QnRF019031; Sat, 25 Dec 2004 10:56:51 +1030 (CST) Subject: Re: [Caml-list] Possibility of Nested Classes and Nested Inheritance? From: skaller Reply-To: skaller@users.sourceforge.net To: Nate Nystrom Cc: caml-list@yquem.inria.fr, Andrew Myers In-Reply-To: References: <20041217184433.GA1036@balm.cs.cornell.edu> Content-Type: text/plain Organization: Message-Id: <1103934408.6201.215.camel@pelican.wigram> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.2 (1.2.2-4) Date: 25 Dec 2004 11:26:49 +1100 Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce with ID 41CCB3D1.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 sourceforge:01 wrote:01 ast:01 expr:01 rec:01 expr:01 variants:01 subtraction:01 subtraction:01 bug:01 glebe:01 48,:98 061:98 constants:01 X-Spam-Checker-Version: SpamAssassin 3.0.0 (2004-09-13) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.0 X-Spam-Level: On Sat, 2004-12-25 at 06:48, Nate Nystrom wrote: > Using the traditional visitor pattern, > you will have to parameterize the visitor class on every AST node class. Given a term for expressions, and a map_expr function which is a functional visitor, I can write: let rec cfold x = match map_expr cfold x with | `Add (`Int a, `Int b) -> `Int (a + b) | other -> other The fact that this formulation admits any number of extra variants without change is a problem! I could add a new term `Sub for subtraction and forget to add the code to fold subtraction of constants. In fact I have done just that, it took several hours to find the bug. -- 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