This preview shows pages 1–2. Sign up to view the full content.
More on the Substitution Model of Evaluation
In this recitation we will review the substitution model we have seen in
last lecture
, and we will give a few
more examples. At the end on the lecture, we will also spend some time on lexical and dynamic scoping. In
the following,
e
will stand for expressions,
v
for values,
p
for patterns and
x,y,z
for variables.
Review of the evaluation rules
Last time we have seen a few rules for evaluating. In these rules, the arrow → just means "reduces to" and is
completely different from the arrows in the function types.
The two main rules for the
if
statements:
if true then
e
1
else
e
2
→
e
1
if false then
e
1
else
e
2
→
e
2
To get an expression of the above form, the first thing the evaluator does is try to reduce the conditional
expression to a boolean value, either true or false ; so if
e
→
v
, then:
if
e
then
e
1
else
e
2
→
if
v
then
e
1
else
e
2
The rule for the
let
statement is:
let
x
=
v
in
e
1
→
e
1
{v/x}
And similarly to what happens for
if
statements, the first thing the evaluator does is try to reduce the value
that will be assigned to
x
, so that if
e
→
v
, then:
let
x
=
e
in
e
1
→
let
x
=
v
in
e
1
Here, we used the notation
e
1
{v/x}
whose idea is "replace all free occurrences of
x
in
e
1
by
v
. More
precisely, this notation can be defined recursively by:
x{e/x} = e
x{e/y} = x
(fun y>e
1
) {e/x} = (fun y>e
1
{e/x})
(fun x>e
1
) {e/x} = (fun x>e
1
)
(let y=e
2
in e
1
) {e/x} = (let y=e
2
{e/x} in e
1
{e/x})
(let x=e
2
in e
1
) {e/x} = (let x=e
2
{e/x} in e
1
)
f(x) { fun y>e
1
/ f } = (fun y>e
1
)(x)
Finally, we want to be able to evaluate function applications. To do that, we first want to evaluate the
argument, then replace the name of the argument by the value of that argument in the body of the function.
The first rule involved here is the fact that if
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This is the end of the preview. Sign up
to
access the rest of the document.
 '07
 GIAMBATTISTA,A

Click to edit the document details