MyBool = Inherit {0, 1} MyBool. Fls = MyBool::__new__ 0 Tru = MyBool::__new__ 1 Expr = Enum { .Lit = Int .Add = {lhs = Expr; rhs = Expr} .Sub = {lhs = Expr; rhs = Expr} .Pos = {expr = Expr} .Neg = {expr = Expr} # .Failure = ... } Expr|<: Show|. show self = match self: Self.Lit(i) -> i.show() Self.Add{lhs; rhs} -> "\{lhs}+\{rhs}" Self.Sub{lhs; rhs} -> "\{lhs}-\{rhs}" Self.Pos{expr;} -> "+\{expr}" Self.Neg{expr;} -> "-\{expr}" Expr. eval self = match self: Self.Lit(i) -> i Self.Add{lhs; rhs} -> lhs.eval() + rhs.eval() Self.Sub{lhs; rhs} -> lhs.eval() - rhs.eval() Self.Pos{expr;} -> +expr.eval() Self.Neg{expr;} -> -expr.eval() expr = Expr.Add {lhs = Expr.Lit(1); rhs = Expr.Lit(2)} print! expr # 1 + 2 assert expr.eval() == 3