Question 12
AQA Computer Science Specimen Paper 2 (7517/2)A level5 marks
On the specification
- 12.1
- 4.12 Fundamentals of functional programming
- 12.2
- 4.12 Fundamentals of functional programming
- 12.3
- 4.12 Fundamentals of functional programming4.1 Fundamentals of programming
Question text
12 In a functional programming language, a recursively defined function named map and a function named double are defined as follows: map f [] = [] map f (x:xs) = f x : map f xs double x = 2 * x The function map has two parameters, a function f, and a list that is either empty (indicated as []), or non-empty, in which case it is expressed as (x:xs) in which x is the head and xs is the tail, which is itself a list. 12.1 In Table 6, write the value(s) that are the head and tail of the list [ 1, 2, 3, 4 ]. [1 mark] Table 6 Head Tail The result of making the function call double 3 is 6. 12.2 Calculate the result of making the function call listed in Table 7. [1 mark] Table 7 Function Call Result map double [ 1, 2, 3, 4 ] 12.3 Explain how you arrived at your answer to question 1 2 . 2 and the recursive steps that you followed. [3 marks]