Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Illuminated

Authors: Catherine M Ricardo, Susan D Urban

3rd Edition

1284056945, 9781284056945

More Books

Students also viewed these Databases questions