Skip to content

Instantly share code, notes, and snippets.

@saturov
Created April 18, 2016 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saturov/27bc8f4445dd83cedb08bb872289724d to your computer and use it in GitHub Desktop.
Save saturov/27bc8f4445dd83cedb08bb872289724d to your computer and use it in GitHub Desktop.
fun eval(expr: Expr): Double = when(expr) {
is Expr.Const -> expr.number
is Expr.Sum -> eval(expr.e1) + eval(expr.e2)
Expr.NotANumber -> Double.NaN
// ветка else не требуется, так как покрыты все возможные сценарии
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment