What is functional programming and how does it differ from imperative programming?
Understand the functional programming paradigm, functions as first-class objects, function application, partial application and composition, and the higher-order functions map, filter and reduce.
A focused answer to AQA A-Level Computer Science 4.13, covering the functional programming paradigm, functions as first-class objects, function application, partial application and composition, and the higher-order functions map, filter and reduce.
Reviewed by: AI editorial process; not yet individually human-reviewed
Have a quick question? Jump to the Q&A page
Jump to a section
What this dot point is asking
AQA wants you to describe the functional programming paradigm, explain that functions are first-class objects, describe function application, partial application and composition, and use the higher-order functions map, filter and reduce (fold).
The functional paradigm
The avoidance of mutable state is the heart of the paradigm and the source of its advantages. Because a pure function cannot alter anything outside itself, its behaviour depends only on its arguments, so it can be tested in isolation, its result can be cached, and several pure functions can run on different processors at once without interfering. This contrasts sharply with the imperative paradigm covered in the languages topic, where the program proceeds by changing the values of variables step by step.
First-class functions, application, partial application and composition
These ideas build on one another. First-class status is the foundation, because only if functions are values can you pass them around to build higher-order functions, compose them, or partially apply them. Partial application and composition are two different ways of making new functions from existing ones: partial application fixes arguments, while composition wires outputs into inputs. Keeping the two clearly apart is a frequent exam discriminator.
Higher-order functions: map, filter and reduce
map(double, [1,2,3]) -> [2,4,6]
filter(isEven, [1,2,3,4]) -> [2,4]
reduce(add, [1,2,3,4], 0) -> 10
These three higher-order functions replace many of the explicit loops of imperative programming with a declarative description of what should happen to the data. Instead of writing a loop that mutates an accumulator, you state that you want every element transformed (map), or the matching ones kept (filter), or all of them combined (reduce). They are often chained: filter the even numbers, then map them to their squares, then reduce by addition, expressing a whole pipeline without a single mutable variable.
Exam-style practice questions
Practice questions written in the style of AQA exam questions on this dot point, with worked answer explainers. The year tag is the paper they imitate, not the source.
AQA 20194 marksExplain what is meant by saying functions are first-class objects in a functional language, and explain the difference between function composition and partial application.Show worked answer →
Functions are first-class objects means a function is treated like any other value: it can be passed as an argument to another function, returned as the result of a function, and stored in a variable. This is what makes higher-order functions possible.
Function composition combines two functions so that the output of one becomes the input of the next: composing f and g produces a new function that applies g first and then f to the result. Partial application instead supplies only some of a function's arguments to produce a new function that takes the remaining arguments; for example fixing the first argument of an add function to make an addFive function.
Markers reward the pass-return-store description of first-class functions and a clear distinction between composition (chaining outputs to inputs) and partial application (fixing some arguments to create a new function).
AQA 20214 marksDescribe the higher-order functions map, filter and reduce, and state the result of applying each to the list [1, 2, 3, 4] with a suitable function.Show worked answer →
A higher-order function is one that takes a function as an argument or returns a function. Map applies a given function to every element of a list and returns a new list of the results. Filter returns a new list containing only the elements that satisfy a given condition. Reduce (fold) combines all the elements into a single value using a given function and a starting value.
Examples on [1, 2, 3, 4]: map with a doubling function gives [2, 4, 6, 8]; filter with an is-even test gives [2, 4]; reduce with addition and a start of 0 gives 1 + 2 + 3 + 4 = 10.
Markers reward correct descriptions of all three higher-order functions and correct results for the worked examples.
Related dot points
- Understand the classification of programming languages by level (low and high) and by paradigm (imperative, object-oriented, declarative and functional), and the use of machine code and assembly language.
A focused answer to AQA A-Level Computer Science 4.6.4, covering the classification of programming languages by level (low and high) and by paradigm (imperative, object-oriented, declarative and functional), and the use of machine code and assembly language.
- Understand classes and objects, attributes and methods, instantiation, encapsulation, inheritance and polymorphism, and the principle of object-oriented design.
A focused answer to AQA A-Level Computer Science 4.1.5, covering classes and objects, attributes and methods, instantiation, encapsulation, inheritance and polymorphism, and the benefits of object-oriented design.
- Understand and use subroutines (procedures and functions), parameters, return values, local and global variables, scope, and the use of an interface and recursion.
A focused answer to AQA A-Level Computer Science 4.1.4 and 4.1.6, covering procedures and functions, parameters and return values, local and global scope, the benefits of subroutines, and recursion.
- Understand the moral, ethical, legal and cultural issues raised by computing, the relevant UK legislation, privacy and data protection, and the responsibilities of computer professionals.
A focused answer to AQA A-Level Computer Science 4.12, covering the moral, ethical, legal and cultural issues raised by computing, the relevant UK legislation, privacy and data protection, and the responsibilities of computer professionals.
- Understand and use the three basic programming constructs (sequence, selection and iteration), definite and indefinite iteration, nested constructs, and the meaning of constants and variables.
A focused answer to AQA A-Level Computer Science 4.1.2, covering the three basic constructs sequence, selection and iteration, definite and indefinite iteration, nesting, and the difference between constants and variables.
Sources & how we know this
- AQA A-level Computer Science (7517) specification — AQA (2015)