Design of Programming Languages - Fall 2005
Final Exam
December 20, 2005
Do any 9.
1. (10 pts)
Operational Semantics and Type Judgments in Impcore
.
(5 pts) Give the operational semantics for
(begin e1 .
.. en)
, where
n
≥
0.
(5 pts) You are given the ARRAY-SET
type
judgment:
Γ
ξ
,
Γ
φ
,
Γ
ρ
⊢
e
1
: ARRAY(
τ
)
Γ
ξ
,
Γ
φ
,
Γ
ρ
⊢
e
2
: INT
Γ
ξ
,
Γ
φ
,
Γ
ρ
⊢
e
3
:
τ
Γ
ξ
,
Γ
φ
,
Γ
ρ
⊢
ARRAY-SET(
e
1
, e
2
, e
3
) :
τ
Within the functiom
fun typeof (e, globals, functions, formals)
of typed Impcore, you have the function
ty
, which takes only the expression
e
as
an argument, using the remaining arguments of
typeof
as free variables and returns
the type of its argument according to the type judgment above. Write the code
completing
ty(ASET(a, i, t))
where
(ASET(a, i, t))
is the appropriate form of
the expression
e
.
2. (10 pts)
Higher Order Functions - either
μ
Scheme or ML.
foldl
is a function
that normally takes three parameters, a binary operator
⊕
, a default value
ℵ
and a
list. Its semantics can be described as:
(foldl
⊕ ℵ
’(
v
1
, v
2
,
···
, v
n
))
=
v
n
⊕
(
v
n
−
1
⊕
(
··· ⊕
(
v
1
⊕ ℵ
)
···
)).
(5 pts) DeFne a
Curried
version of
foldl
.
(5 pts) Using
this version
of
foldl
deFne a function - in the same language as
the Frst part - that will take a list of integers and return the sum of their squares.
You must apply
foldl
to an appropriate binary operator and an appropriate default
value.
1