Last active
July 9, 2017 16:12
-
-
Save nomisRev/bc80502c4d972a9536a638436e09c9d7 to your computer and use it in GitHub Desktop.
Evaluation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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