This mini-lesson covers AQA 4.12 — Fundamentals of functional programming. It is a genuinely different way of thinking: you stop giving the machine orders and start describing relationships between values.
Work through each screen, answer the questions as you go (some are recall, some are calculations you must actually work out) and collect ⭐ stars. Press Start when you're ready.
In functional programming a function is a mapping from one set of values to another — a mathematical object, not a list of commands.
Function application is simply giving a function its argument: square 4 evaluates to 16. Notice there is no assignment, no loop and no state — just a value being replaced by another value.
Why the type matters: the type is a contract, checkable before the program ever runs. If a function claims ℤ → 𝔹 and you try to add 1 to its result, the compiler rejects it. A whole class of bugs becomes unrepresentable.
A first-class object is anything the language will let you treat like an ordinary value. In a functional language, functions are first-class:
A function that takes a function as a parameter, or returns one, is called a higher-order function. This is what makes functional code so compact — the general pattern (looping over a list) is written once, and you supply the specific behaviour.
Partial function application: supply some arguments now and get back a new function awaiting the rest.
The payoff: partial application lets you build specialised functions out of general ones with no boilerplate at all. add5 was created without writing a new definition.
Composition chains functions together: the output of one becomes the input of the next.
f(x) = 2x + 1 g(x) = x²
(f ∘ g)(3) = f(g(3)) = f(9) = 2(9) + 1 = 19
(g ∘ f)(3) = g(f(3)) = g(7) = 7² = 49
Composition is not commutative — the order changes the answer, as those two lines show. This trips people up constantly.
Why this is powerful: a large program becomes a pipeline of small, individually testable functions. Each does one thing; composition assembles them. Compare the imperative alternative, where behaviour is smeared across loops and mutable variables and cannot be tested in isolation.
These three higher-order functions replace almost every loop you have ever written.
| Function | What it does | Result |
|---|---|---|
| map | Applies a function to every element | A list of the same length |
| filter | Keeps only the elements that pass a test | A list of the same or shorter length |
| reduce / fold | Combines all elements using a function and a starting value | A single value |
Chained together, that reads as: square everything, keep what is bigger than 5, add up what remains. Three lines, no loop counter, no mutable accumulator, no off-by-one error.
Note the shapes: map preserves length; filter can only shrink it; reduce collapses it to one value. If an exam question asks which function could turn a list of 6 into a list of 6, the answer is map — never filter.
In a purely functional language, data is immutable: once a value exists it can never be changed. "Changing" a list means producing a new list. Nothing is overwritten, so:
Standard list operations:
head and tail are the engine of recursion: nearly every functional list algorithm is "do something with the head, then recurse on the tail, stopping when the list is empty". That is the functional replacement for a for-loop.
Tap the description, then tap the function it describes.
Tap an item on the left, then its partner on the right.
Types: function type = domain → co-domain · application = giving a function its argument
First-class: functions can be assigned, passed, returned and stored — that is what enables higher-order functions
Composition: (f ∘ g)(x) = f(g(x)) — right to left, and not commutative
Higher-order: map (same length) · filter (same or shorter) · reduce/fold (one value)
Partial application: add5 = add 5 — supply some arguments now, get a new function back
Immutability: no side effects · referential transparency · safe concurrency without locks
Lists: head · tail · prepend · append · length — head plus recursion on the tail replaces the loop
That is the whole of AQA 4.12. Press Finish to see your score.
You've worked through Functional programming for AQA A-level Computer Science (7517). 🎉
Your stars: 0 / 0
Next: test yourself in the Evaluate stage Confidence Quiz, then lock it in with Verify.