3 datatype Replaced<T> = REPLACED of T
7 | ADD of Exp, Exp => "(" _ "+" _ ")"
8 | FINAL of Replaced<Exp> => "FINAL(" _ ")"
11 ostream& operator << (ostream& f, Replaced<Exp> e);
13 instantiate datatype Exp, Replaced<Exp>;
15 ostream& operator << (ostream& f, Replaced<Exp> e)
16 { match (e) of REPLACED e: { return f << "REPLACED(" << e << ")"; }
20 rewrite class Silly (Exp) {
26 NUM 0: FINAL(REPLACED(NUM(1)))
27 | NUM x: FINAL(REPLACED(NUM(2)))
32 Exp e = ADD(NUM(0),NUM(3));
34 cout << "Before = " << e << '\n';
36 cout << "After = " << e << '\n';
37 rewrite (e) type (Exp,Replaced<Exp>) {
40 cout << "Finally = " << e << '\n';