In functional programming, a list can be defined as a concatenation of two specific components. What are these two components called?
Example: in Haskell, the list \([4, 3, 5]\) can be written as \(4:[3, 5]\).
AQA A Level · Computer Science 7517
Lists in functional programming: Practice Questions
5 multiple-choice questions marked as you go, and 5 written questions with worked solutions. All on Lists in functional programming.
Given the list \(L = [10, 20, 30, 40]\), what would be the result of the operation prepend \(5\) to \(L\)?
Let \(L = [5, 12, 18, 21]\). Consider a recursive function f:
\(f([]) = 0\)
\(f(head:tail) = 1 + f(tail)\)
What is the result of applying \(f(L)\)?
If a list \(L\) is defined as \(7:[2, 9, 1]\), what is the result of the operation that returns the tail of the list?
In functional list processing, how is the list \([1, 2, 3, 4]\) represented using recursive construction with the empty list symbol \([]\)?
What is the resulting list when you prepend the item \( 5 \) to the list \( [12, 15] \)?
Write your answer out first, then check it against the worked solution.
A programmer uses a function to test for an empty list. If the input is \( head:tail \), what is the Boolean result of this test?
Write your answer out first, then check it against the worked solution.
A programmer is using Lists in functional programming. If a list is constructed as \( L = x:xs \), describe the result of the operation head(tail(tail([1, 2, 3, 4]))).
Write your answer out first, then check it against the worked solution.
A list in a functional language is often represented as a head and a tail.
(a) Define what is meant by the 'head' and 'tail' of a list.
(b) Given the list \( L = [10, 20, 30, 40] \), show how this list would be represented using the construction operator (often denoted as a colon \( : \) in Haskell) and the empty list symbol \( [] \).
Write your answer out first, then check it against the worked solution.
A programmer is writing a functional program to process a list of integers.
(a) Write a recursive definition for a function length(L) that returns the number of elements in a list \( L \). You should use the concepts of head, tail, and empty list.
(b) Trace your function with the list \( [7, 3] \), showing each recursive call.
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