Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re: [Caml-list] Possibility of Nested Classes and Nested Inheritance?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: skaller <skaller@u...>
Subject: Re: [Caml-list] Possibility of Nested Classes and Nested Inheritance?
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