Question: 5. (2 points) Operation Semantics Rules (a) (1 point) Consider the operation semantics rules for function calls (or function applications) presented in Lecture 11 or

5. (2 points) Operation Semantics Rules (a) (1 point) Consider the operation semantics rules for function calls (or function applications) presented in Lecture 11 or Assignment 4: EAGEREval A;e1e2v2A;e1(funxe)A;e2v1A,x:v1;ev2 We call this rule EAGEREval because it evaluates the function application argument e2 to a value before evaluating the function body e from e1. Using this evaluation rule, the interpreter can reduce the OCaml program (fun x fun yxy1 ) (fun c c) (( fun aa)( fun bb)) in the following few steps (we omit the environment A for simplicity): (funxfunyxy1)(funcc)((funaa)(funbb))(funy(funcc)y1)((funaa)(funbb))(funy(funcc)y1)(funbb)(funcc)(funbb)1(funbb)11 It is important to note that function application is left-associative e.g. xyz=(xy)z. We now define a new function application evaluation rule called LAZYEvAL as follows: LAZYEvaL A;e1e2v2A;e1(funxe)A;e{e2/x}v2 Here, e{e2/x} means "the expression after substituting occurrences of x in e with e2 ". The key point is that we defer the evaluation of the functional application argument e2 until it has to be evaluated. This is often referred as "lazy evaluation". Reduce the same OCaml program (fun x fun yxy ) (fun cc)(( fun a a) (fun bb )) using this new evaluation rule to witness the key difference between EAGEREval and LAzyEval
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
