Question: 5 . ( 2 points ) Operation Semantics Rules ( a ) ( 1 point ) Consider the operation semantics rules for function calls (

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 ; e_1( fun x -> e) A ; e_2 v_1 A, x: v_1 ; e v_2/A ; e_1 e_2 v 2 We call this rule EAGEREval because it evaluates the function application argument e_2 to a value before evaluating the function body e from e_1. Using this evaluation rule, the interpreter can reduce the OCaml program (fun x -> fun y -> x y 1)(fun c -> c)(( fun a -> a)( fun b -> b)) in the following few steps (we omit the environment A for simplicity): [( fun x -> fun y -> x y 1)( fun c -> c)(( fun a -> a)( fun b -> b)); ( fun y ->( fun c -> c) y 1)(( fun a -> a)( fun b -> b)); ( fun y ->( fun c -> c) y 1)( fun b -> b); ( fun c -> c)( fun b -> b)1; ( fun b -> b)1; 1] It is important to note that function application is left-associative e.g. x y z=([ x y ]) z. We now define a new function application evaluation rule called LAZYEvAL as follows: LAZYEvaL A ; e_1( fun x -> e) A ; e{e_2/ x} v_2/A ; e_1 e_2 v 2 Here, e{e_2/ x} means "the expression after substituting occurrences of x in e with e_2". The key point is that we defer the evaluation of the functional application argument e_2 until it has to be evaluated. This is often referred as "lazy evaluation". Reduce the same OCaml program (fun x -> fun y -> x y )(fun c -> c)(( fun a -> a)(fun b -> b )) 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!