namespace; include rt; // tagged enums: a member can carry fields, a constructor builds it, and a // switch matches on the member and binds its fields enum shape { circle { int r; }, rect { int w; int h; }, dot }; fn area(shape* s) { switch (s) { case circle(r): return r * r * 3; case rect(w, h): return w * h; case dot: return 0; } return -1; } fn main() { shape* a = shape.circle(3); shape* b = shape.rect(4, 5); shape* c = shape.dot(); rt.put_n(area(a)); rt.put_c(32); rt.put_n(area(b)); rt.put_c(32); rt.put_n(area(c)); rt.put_c(32); rt.put_n(a.tag); rt.put_c(32); rt.put_n(b.tag); rt.put_c(32); rt.put_n(c.tag); rt.put_c(10); rt.free(d*a); rt.free(d*b); rt.free(d*c); return 0; }