``` fun eval(expr: Expr): Double = when(expr) { ...
# language-proposals
o
Copy code
fun eval(expr: Expr): Double = when(expr) {
  is Expr.Const -> expr.number
  is Expr.Sum -> eval(expr.e1) + eval(expr.e2)
  is NotANumber -> Double.NaN
}
This will work, and if you add
Product
that will cause compile-time error
­čĹî 2