Question: Question 9 : Consider the Scala definitions: enum Exp: case Val ( n:Int ) case Plus ( e 1 :Exp, e 2 :Exp ) case
Question : Consider the Scala definitions:
enum Exp:
case Val n:Int
case Plus e:Exp, e:Exp
case Times e:Exp, e:Exp
def f e:Exp : Int e match
case Val v v
case Plus e e f e f e
case Times e e f e f e
With the above definitions, what is the outcome of running the following Scala code?
val sample Times Plus Val Val Val
println f sample
A : The code runs successfully and prints:
B : The code fails to compile because the parameter to Val is called n in the class declaration, but is called v in the
function f
C : The code fails to compile because the parameter to Val is not a single Int but an expression
D : The code runs successfully and prints:
E : The code runs successfully and prints:
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
