I have already written the code and the code is getting executed successfully … For some reason while coming out of the simulation test, It says it is not completed yet… Can you please have a kindly check from your expertise point of view, Is there any gap ?.. thanks!
abstract class Expression
case class Var(name: String) extends Expression
case class Number(num: Double) extends Expression
case class UnOp(operator: String, arg: Expression) extends Expression
case class BinOp(operator: String, left: Expression, right: Expression) extends Expression
object CaseClassMatching extends App {
def describe(exp: Expression): String =
exp match {
case Var(_) => "It is a string expression"
case Number(d) => "It is a number"
case UnOp(op, arg) => "It is a unary expression"
case BinOp(op, left, right) => "It is a binary operation"
//case _ => "Invalid Expression"
}
val op = BinOp("+", Number(1), Number(4))
println(describe(op))
(When asking questions on the Internet, even if you manage to fix the problem yourself, it’s always polite to say what the solution was, in case someone else runs into the same thing.)
abstract class Expression
case class Var(name: String) extends Expression
case class Number(num: Double) extends Expression
case class UnOp(operator: String, arg: Expression) extends Expression
case class BinOp(operator: String, left: Expression, right: Expression) extends Expression