name_or_number: @union type = { name: std::string; num : i32; } name_or_other: @union type = { name : std::string; other : T; to_string: (this) -> std::string = { if is_name() { return name(); } else if is_other() { return other() as std::string; } else { return "invalid value"; } } } print_name: (non: name_or_number) = { if non.is_name() { std::cout << non.name() << "\n"; } else { std::cout << "(not a name)\n"; } } main: () = { x: name_or_number = (); std::cout << "sizeof(x) is (sizeof(x))$\n"; x.print_name(); x.set_name( "xyzzy", 3 as u8 ); x.print_name(); { val: name_or_other = (); val.set_other(42); std::cout << val.to_string(); } }