Candidate Number
G6021
Comparative Programming
DO NOT TURN OVER UNTIL INSTRUCTED TO BY THE LEAD INVIGILATOR Candidates should answer TWO questions out of THREE. If all three questions are attempted only the first two answers will be marked.Add The time allowed is TWO hours.
At the end of the examination the question paper and any answer books/answer sheets, used or unused, will be collected from you before you leave the examination room.
G6021 Comparative Programming
(b) • Describe briefly the call-by-name and call-by-value strategies of evaluation of functions, highlighting the differences between them.
• Consider the two functions zero and loop below: zero :: Integer -> Integer zero x = 0
loop :: Integer -> Integer loop x = loop
(x + 1)
(c) Consider the following definition of the function iterate_until:
iterate_until p f x = if (p (f x)) then (f x)
else iterate_until p f (f x)
2. (a) Consider the λ-term t = vw(λxy.vx).
i. Write t in full, inserting all the missing parentheses and λ’s. ii. List the free variables and bound variables of t.
(b) Give the β-reduction graph of the λ-term (λxy.x)(II)I, where I = λx.x.
Add
Turn over/
G6021 Comparative Programming
3. This question is about comparing paradigms for adding an element at the end of a list.
(a) Consider the following logic program defining the insertion of an element at the end of a list.
insert(X,[],[X]). insert(X,[S1|S],[S1|S2]) :- insert(X,S,S2).
Draw the SLD-resolution tree for the query:
:- insert(1,[2],Y).
(b) Write a polymorphic Haskell function insert to add an element at the end of a list. Include in your answer:
• The type of your function.
• A reduction graph of insert 2 [1].
(c) Compare the different paradigms studied in this module for adding an element to the end of a list. Your answer should incorporate features of different paradigms such as Prolog difference lists, accumulating parameters, objects, and any other appropriate concept to justify your
Add
End of Paper



