OOP and Functional Programming Homework 5
OOP and Functional Programming Homework 5
(c) null (tail (tail( tail ( tail (tail (tail fish )))))) [1]
(a) prepend the numbers 5, 10 to the list num1 = [15, 20, 25], storing the result
in num2. [2]
(b) append the numbers 30, 35, to the list num2, storing the result in num3. [2]
(c) Why is it not possible to append numbers to num2, leaving the result in num2? [1]
(d) What would be the result of concatenating the lists num2 and num3? [1]
3. Readings from a sensor are stored in the list humidity = [45, 67, 81, 73, 62, 41]
What is returned by these function calls?
1
Homework 5 Lists
Unit 12 OOP and functional programming
4. In Haskell, strings of characters can be treated as lists. The following list contains 3 strings:
sentence = ["Here", "we", "are"]
(a) length is a function which returns the number of elements in a list.
(i) Write a statement which will return the number of strings in sentence. [1]
(ii) map is a function which takes a list and the function to be applied to the elements
in the list, and returns a list made by applying the function to each element of the
list.
Write a statement which will return a list containing the lengths of each
word in the list sentence given above. [2]
[Total 20 Marks]