COMP3161/COMP9161
Concepts of Programming Languages
Sample Exam
Session 2 2011
Question 1 [25 Marks]
Consider the following inductive deο¬nition of evaluation rules for a restricted form of boolean expres- sions.
Boolean expressions:
Evaluation rules:
A) [7 marks]
Give the derivation of the evaluation for the following expression:
β’ and(not(false); and(true; not(true)))
B) [7 marks]
Are the rules unambiguous? If so, brieο¬y explain why. If not, give an example expression for which the set of rules allow more than a single derivation.
C) [11 marks]
The rules listed above give a small step semantics. List the inference rules which specify an equiv- alent big step semantics.
Question 2 [25 Marks]
A) [10 marks]
In the lecture, we discussed the E-machine as an example of an abstract machine which handles value bindings explicitly by maintaining a value environment. One of the possible return values of the E-machine are function closures.
i) What is a function closure?
ii) Give an example of an expression whose evaluation in the E-machine requires the creation of a closure.
B) [15 marks]
We discussed two distinct methods to handle exceptions: the ο¬rst method required that, when an exception is thrown, the evaluation unrolls the stack until the matching catch-expression is found. The second method made it possible to directly jump to the matching catch-expression. Describe the second method:
i) What are the components of the state of the abstract machine?
ii) How does the state of the machine change when a catch-expression is evaluated?
iii) How does the state of the machine change when a raise-expression is evaluated?
For (ii) and (iii), you do not have to give the exact transition rule β it is sufο¬cient to describe how the state is affected.
Question 3 [25 Marks]
A) [6 marks]
For each of the following three pairs of type expressions determine whether the pair has a most general uniο¬er? If so, please provide it.
i) (a , b) β (b , a) and (int , c) β (c , c)
ii) a β (a , a) and (b , b) β b
iii) int β int and float β int
B) [9 marks]
Give the principal type of the following (polymorphic) MinHs expressions:
i) Inr(Inl(True))
ii) letfun f (x) is fst (snd (x));
iii) letfun g (x) is
case x of Inl(a) -> a
Inr(b) -> b
end
end
C) [10 marks]
Consider the following MinHs types:
β’ 8a.8b.(a * b β c) β (a β b β c)
β’ 8a.8b.(a β b) β (b β a)
β’ 8a.8b.8c.(a β b) β (b β c) β (c β a)
β’ 8a.() β a
β’ 8a.a β ()
For which of these types exist terminating MinHs functions?
Question 4 [25 Marks]
A) [10 marks]
Progress and preservation are central concepts for strongly typed languages.
i) Give the deο¬nition of progress and of preservation in the context of a strongly typed language.
ii) The presence of partial functions can be problematic with respect to progress. Describe how they can be handled in a strongly typed language such that both progress and preservation still hold.
B) [5 marks]
Give an example each for a type constructor which is covariant and a type constructor which is contravariant in at least one of its argument positions.
C) [10 marks]
Javaβs array type is covariant. Why is this problematic?

![[SOLVED] COMP3161/COMP9161 Concepts of Programming Languages Session 2 2011 Java](https://assignmentchef.com/wp-content/uploads/2022/08/downloadzip.jpg)

![[Solved] program that will merge the contents of the text files located in the given folder](https://assignmentchef.com/wp-content/uploads/2022/08/downloadzip-1200x1200.jpg)
Reviews
There are no reviews yet.