EuraStudy
Functional programming is a paradigm that treats computation as the evaluation of mathematical functions, avoiding changing state and mutable data. This chapter develops functions as first-class objects, purity and the absence of side effects, function application, composition and partial application, the higher-order functions map, filter and fold, and the list-processing operations that are its natural data structure. Its importance is amplified by its role in the safe parallelism of big-data processing.
4 sections~14 min reading time3 competenciesLevel Standard 1 · Advanced 3
basic level
The functional paradigm is primarily A-Level content; AS students meet functions and simple list ideas.
higher level
The full A-Level expects first-class functions, function application, composition and partial application, the higher-order functions map/filter/fold, and list processing.
Reading depth: In depth
Text size: Standard
A function as a mapping from domain to co-domain
A function's type
maps each element of the domain to exactly one element of the co-domain ; the type signature states and .
Classify each as pure or impure and justify: (a) double(x) returns 2*x; (b) addToLog(x) appends x to a global log and returns x; (c) roll() returns a random number.
Its result depends only on x and it changes nothing external - pure. double(5) is always 10, so it is referentially transparent.
It modifies external state (the global log) - a side effect - so it is impure, even though it also returns a value.
It returns a different value each call, so its output does not depend only on its inputs - impure (and not referentially transparent).
Result: Only double is pure. Purity requires the output to depend solely on the inputs with no side effects, which is why only (a) qualifies.
Typical mistakes
Active revision
State whether each is a pure function and why: (a) one that returns the square of its argument; (b) one that adds its argument to a running global total; (c) one that returns the current time. Give the domain and co-domain of a function that maps a string to its length.
Active recall
Recall the key points — then reveal.
Sources: GCE AS and A level subject content for computer science (Department for Education) · AQA A-level Computer Science 7517 specification (AQA)
Function composition as a pipeline
Function composition
Apply first, then ; the order matters, so in general .
With f(x) = x + 1 and g(x) = 2x, evaluate (g o f)(3) and (f o g)(3). Then, from add(x, y) = x + y, partially apply to make addTen and evaluate addTen(7).
Apply f first: . Then g: .
Apply g first: . Then f: . So the two compositions differ (8 vs 7) - order matters.
Fix x = 10 in add to get addTen(y) = 10 + y. Then addTen(7) = 10 + 7 = 17.
Result: (g o f)(3) = 8, (f o g)(3) = 7 (different), and addTen(7) = 17. Composition respects order; partial application specialises a general function.
Typical mistakes
Active revision
Given and , evaluate and and confirm they differ. Then, from a function , use partial application to define and evaluate .
Active recall
Recall the key points — then reveal.
Sources: AQA A-level Computer Science 7517 specification (AQA)
A map-filter-fold pipeline
For the list [1, 2, 3, 4, 5], give the result of: (a) map (add 10); (b) filter (greater than 2); (c) fold with multiplication starting at 1.
Apply 'add 10' to each element: - same length, each transformed.
Keep only elements greater than 2: - 1 and 2 are removed, so the list is shorter.
Combine all elements by multiplication from 1: .
Result: (a) [11, 12, 13, 14, 15]; (b) [3, 4, 5]; (c) 120. map transforms, filter selects, fold reduces to one value - three loops expressed declaratively.
Typical mistakes
Active revision
Starting from the list [1, 2, 3, 4, 5, 6], apply filter with 'is even', then map with 'square', then fold with addition (start 0). Show each intermediate list and the final value.
Active recall
Recall the key points — then reveal.
Sources: AQA A-level Computer Science 7517 specification (AQA)
A list as head and tail
For the list [8, 6, 4, 2], give the head, tail, the result of prepending 9, and the length. Then outline a recursive sum using head, tail and isEmpty.
head = 8; tail = [6, 4, 2]; prepending 9 gives [9, 8, 6, 4, 2]; length = 4.
A recursive sum needs a base case: if the list isEmpty, its sum is 0.
Otherwise the sum is head + sum(tail): here 8 + sum([6, 4, 2]) unwinds to .
Result: head 8, tail [6,4,2], prepend gives [9,8,6,4,2], length 4; the recursive sum unwinds to . Head/tail with an empty-list base case is the functional loop.
Typical mistakes
Active revision
For the list [8, 6, 4, 2], give the head, the tail, the result of prepending 10, and the length. Then describe how you would sum a list recursively using head, tail and the empty-list test.
Active recall
Recall the key points — then reveal.
Sources: AQA A-level Computer Science 7517 specification (AQA)
References & sources
Department for Education