//package straightparse;
abstract class List {
public abstract A accept (ListVisitor v);
public abstract int len();
public abstract List reverse ();
public abstract List reverse0 (List acc);
public abstract String toString();
}
class NIL extends List {
public NIL () { }
public int len() { return 0 ; }
public List reverse () { return this; }
public List reverse0 (List acc) { return acc; }
public String toString() { return "" ; }
public A accept (ListVisitor v) {
return v.visit (this);
}
}
class CONS extends List {
public a hd;
public List tl;
public CONS (a x, List xs) {
this.hd = x;
this.tl = xs;
}
public int len() { return 1 + tl.len() ; }
public List reverse () { return this.reverse0(new NIL()) ;}
public List reverse0 (List acc) { return this.tl.reverse0(new CONS(this.hd,acc)) ;}
public String toString() { if (this.tl instanceof NIL) {
return this.hd.toString();
} else {
return this.hd.toString() + "," + this.tl.toString();
} }
public A accept (ListVisitor v) {
return v.visit (this);
}
}
interface ListVisitor {
public A visit (NIL m);
public A visit (CONS m);
}