Computer Science Applications Report – Task D
Detail of the task
AS1
1. Define a polymorphic function palindrome to form a palindrome from an arbitrary list.
For example:
>: palindrome “mad”; >: palindrome “abcd”;
>> “madam”: list char >> “abcdcba” : list char [5 marks]
2. (a) (i) Define a polymorphic function larger to determine the larger of two numbers (or two chars).
(ii) Define a polymorphic function largest to find largest element of a list of numbers (or list of
chars). You can assume that function largest is not defined over empty lists as it does not make
sense to find the largest of an empty list. Also assume that if the input is a list of chars then all the
chars are alphabetic (lower case) letters.
For example:
>: largest [4, 3, 5, 8, 2]; >: largest “hope”;
>> 8 : num >> ‘p’: char [5 marks]
(b) Write the sequences of reductions for the following application of the higher-order function compress,
where alist is the first three characters of your surname:
compress(larger, alist) [10 marks]
3. Expression map(f, alist) is equivalent to expression reduce( lambda (n, l) => f n :: l, nil, alist ).
Show that an application of the both expressions gives the same result by writing the sequences of
reductions for some function f and alist, where alist is the first three characters of your surname. You
should give the definition of the function f. [10 marks]
AS2
Show how ‘HOPE machine’ evaluates your functions and displays the results. [3 marks]
What you should hand in
1. A PDF document with your solutions to the questions (1) – (3) from AS1 and
screenshot(s) showing ‘HOPE machine’ evaluating your functions and displaying the results for
AS2. You should give all the definitions of the functions used in your solutions.
2. The *.hop file where you saved all the functions used for this task. Note that your answers will
not be assessed without this file.