Skip to content

Instantly share code, notes, and snippets.

@nomisRev
Last active July 9, 2017 16:12
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 nomisRev/bc80502c4d972a9536a638436e09c9d7 to your computer and use it in GitHub Desktop.
Save nomisRev/bc80502c4d972a9536a638436e09c9d7 to your computer and use it in GitHub Desktop.
Evaluation
sealed class MathExpression {
abstract fun eval(): Int
}
data class Addition(val left: MathExpression, val right: MathExpression) : MathExpression() {
override fun eval(): Int = left.eval() + right.eval()
}
data class Subtraction(val left: MathExpression, val right: MathExpression) : MathExpression() {
override fun eval(): Int = left.eval() - right.eval()
}
data class Number(val value: Int) : MathExpression() {
override fun eval(): Int = value
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment