AQA A Level · Computer Science 7517

Writing functional programs: Practice Questions

5 multiple-choice questions marked as you go, and 5 written questions with worked solutions. All on Writing functional programs.

10 questions25 marksFree, no account
Question 1
1 mark

In Haskell, given the list [10, 20, 30], what is the tail of this list?

Question 2
1 mark

What is the result of the following function composition?
Let \(f(x) = x + 1\) and \(g(x) = x^2\).
Find \((g \circ f)(3)\).

Question 3
1 mark

Given the following Haskell-style list definition:
myList = [x * 2 | x <- [1..5], x > 2]

What is the final value of myList?

Question 4
1 mark

In a functional language like Haskell, if a list is defined as [7, 2, 9], what are the head and tail of this list respectively?

Question 5
1 mark

Which functional programming operation is best described as reducing a list of values to a single value by repeatedly applying a combining function?

Question 6
2 marks

Identify the result of applying the list operation tail to the Haskell list \([10, 20, 30]\).

Write your answer out first, then check it against the worked solution.

Question 7
3 marks

Explain the difference between a higher-order function and a standard first-order function.

Write your answer out first, then check it against the worked solution.

Question 8
5 marks

A list is represented in Haskell notation as head:tail. If a list is defined as \(L = [7]\), state the values of the head and the tail.

Write your answer out first, then check it against the worked solution.

Question 9
3 marks

Describe the purpose of the following higher-order functions commonly used in functional programming:

(a) map
(b) filter
(c) reduce (also known as fold)

Write your answer out first, then check it against the worked solution.

Question 10
7 marks

A high-order function foldright (or reduce) is defined. It takes a combining function \( f \), an initial value \( z \), and a list.

Let \( f(x, acc) = x - acc \) and the initial value \( z = 0 \).

(a) Calculate the result of applying this fold operation to the list \( [5, 10, 15] \) using right-associativity: \( f(5, f(10, f(15, 0))) \).
(b) Explain how the result would differ if left-associativity (foldleft) was used with the same function and initial value: \( f(f(f(0, 5), 10), 15) \).
(c) Why is the choice of associativity important for non-commutative operations like subtraction?

Write your answer out first, then check it against the worked solution.

* The content provided by thinka is generated by AI and may not always be accurate or up-to-date. Please use it as a supplementary resource and verify with official materials.

You've seen the model answer. Now get yours marked.

This page can show you how a good answer looks. It cannot tell you what your answer was missing. thinka marks your written work against the real mark scheme in about 15 seconds.

Want more questions like these? Get a fresh set on this topic, marked as you go.

Practise More