Skip to topic
    ← Back to course topics

    Function type — AQA A-Level Computer Science

    In AQA A-Level Computer Science, a function type defines the notation and mapping between a set of inputs (the domain) and the set of permissible outputs (the co-domain), denoted as 'f : A -> B'. Understanding function types is foundational to functional programming, where functions are treated as first-class objects that can be passed as arguments, returned, and partially applied.

    Function type explained

    A function maps each element of one set to exactly one element of another set.

    Read the full explanation

    The domain is the first of these two sets: it is the collection of all permitted input values. Every input the function is asked to process must be drawn from the domain, and the function is only defined for those inputs. For example, if f(x) = 2x + 1 is defined with a domain of the integers {1, 2, 3}, then f(1) = 3, f(2) = 5 and f(3) = 7 are the only valid results, and f(4) cannot be evaluated because 4 is outside the domain. Choosing a domain therefore restricts what the function accepts, and a student must always state the input set before discussing a function's behaviour. The domain is distinct from the set of outputs, which is covered by the co-domain.

    Your focus

    1. The domain is a set from which the function’s input values are chosen.

    Which command word is this?

    Give a concise, precise fact or formula without commentary (e.g. 'State the type signature of the function').

    Function type exam tips

    Topic Overview

    Function types are an essential component of the functional programming paradigm in AQA A-Level Computer Science. Unlike imperative programming where subroutines execute sequences of commands modifying global state, functional programming models computation strictly as the mathematical evaluation of functions. A function type formally defines the transformation from an input data type to an output data type.

    Mastering function types enables students to understand higher-order functions, currying, and partial application. This topic bridges theoretical discrete mathematics with modern software engineering practices, providing the foundational vocabulary needed to interpret Haskell-like type signatures and reason about type safety.

    Key Concepts
    • →Domain and Co-domain: The domain is the set of all allowable input values, while the co-domain is the set from which all possible output values must come.
    • →Arrow Notation: Written as 'f : A -> B', denoting that function 'f' takes an argument of type 'A' and returns a value of type 'B'.
    • →First-Class Objects: Entities that can be passed as arguments, returned from subroutines, and bound to variable names or stored in data structures.
    • →Higher-Order Functions: Functions that accept one or more functions as arguments, return a function as a result, or both (such as map, filter, and fold).
    • →Partial Application: The process of applying a function to fewer arguments than it expects, yielding a new function with a reduced type signature.
    Marking Points
    • Identifies the domain as the set of permitted input values.
    • Explains that every input to the function must be an element of the domain.
    • Gives a concrete example showing an input inside and outside a stated domain.
    • Distinguishes the domain (inputs) from the co-domain (outputs).
    Examiner Tips
    • 💡Identify the input set first when asked about any function.
    • 💡Test whether a given value is inside the domain before evaluating a function.
    • 💡Keep the terms domain and co-domain clearly separate in your answers.
    • 💡Use standard brackets when grouping function parameters inside type signatures; for instance, write '(a -> b) -> [a] -> [b]' rather than omitting brackets around higher-order parameters.
    • 💡Be precise with uppercase and lowercase letters in exam type signatures: specific concrete types begin with capital letters (e.g. 'Int', 'Char'), whereas generic type variables use lowercase letters (e.g. 'a', 'b').
    • 💡When explaining higher-order functions, explicitly cite standard examples required by the AQA specification: 'map', 'filter', or 'fold/reduce'.
    Common Mistakes
    • Treats the domain as the set of output values; correct the reasoning by identifying it as the set of inputs.
    • Confuses the domain with the range, which is the set of values actually produced; correct by noting the range is the actual outputs.
    • Assumes every function has an unrestricted domain; correct by stating the domain is chosen or specified for each function.
    • Believing that 'co-domain' and 'range' are identical: The range (or image) consists only of the actual values produced by the function, whereas the co-domain is the entire set of possible values defined by the output type.
    • Assuming functions with multiple arrows evaluate all arguments simultaneously: Functional type signatures like 'A -> B -> C' are right-associative and represent 'A -> (B -> C)', meaning arguments are consumed one at a time.
    • Confusing partial application with incomplete or broken execution: Partial application is a deliberate, valid programming technique that creates specialised reusable functions.
    Revision Plan
    1. 1Day 1-2: Review mathematical set definitions for domain, co-domain, and range, and practise writing basic signatures 'f : A -> B'.
    2. 2Day 3-4: Learn the definition of first-class objects and practise constructing curried function types with two or three parameters.
    3. 3Day 5-6: Study higher-order functions ('map', 'filter', 'fold') and write down the full type signatures for each using type variables.
    4. 4Day 7: Practise AQA past exam questions focusing on partial application and explaining functional type signatures.
    Exam Question Types
    • 📋Type signature interpretation: Given a signature like 'calculate : Int -> (Int -> Bool)', explain the domain, co-domain, and behaviour.
    • 📋Writing signatures: Provide the type signature for a described utility function (e.g. a predicate checker or list transformer).
    • 📋Conceptual definitions: 2-4 mark questions asking for definitions and characteristics of first-class functions, higher-order functions, or partial application.
    • 📋Tracing partial application: Stating the resulting type signature after supplying one argument to a multi-argument function.
    Command Word Expectations (AQA)
    State

    Give a concise, precise fact or formula without commentary (e.g. 'State the type signature of the function').

    Explain

    Set out reasons or mechanisms clearly, demonstrating how a functional concept works (e.g. explaining what partial application achieves with technical vocabulary).

    Describe

    Provide the main characteristics of a concept, such as outlining the three attributes that qualify functions as first-class objects.

    How Students Lose Marks (Examiner Pitfalls)
    Pitfall: Confusing the domain and the co-domain in functional type signatures or reversing their order.
    ❌ Weak Answer (Loses Marks):A function type shows the output and what numbers go into it, such as Integer coming from Boolean.
    Example improved answer:A function type signature written as 'f : A -> B' denotes that 'A' represents the domain (the set of valid input values) and 'B' represents the co-domain (the set of possible output values).
    Examiner Tip: Always read '->' as 'maps to'. The type on the left is strictly the input (domain), and the type on the right is strictly the output (co-domain).
    Pitfall: Vaguely defining a 'first-class object' or 'first-class citizen' without specifying the three core technical capabilities.
    ❌ Weak Answer (Loses Marks):Functions are first-class because they are important and can be used anywhere in the code like regular functions.
    Example improved answer:In functional programming, functions are first-class objects because they can be assigned to variables, passed as arguments to other functions, and returned as values from functions.
    Examiner Tip: Memorise the exact three-part definition of a first-class object: assigned to variable/data structure, passed as argument, returned as result.
    Step-by-Step Worked Solutions

    Question: A higher-order function named 'map' applies a function to every item in a list. Write the type signature for 'map' where a function converts an integer to a boolean, applied across a list of integers to yield a list of booleans.

    1. 1.Step 1: Identify the transformation function input and output types. The transformation takes an Integer and returns a Boolean, so its type is '(Integer -> Boolean)'.
    2. 2.Step 2: Identify the input list type. The input is a list of integers, denoted as '[Integer]'.
    3. 3.Step 3: Identify the output list type. The result is a list of booleans, denoted as '[Boolean]'.
    4. 4.Step 4: Combine the component types using the function arrow notation, remembering that curried functions chain with right-associativity.
    Final Answer: map : (Integer -> Boolean) -> [Integer] -> [Boolean]

    Question: Consider the function type signature 'multiply : Int -> Int -> Int'. Explain what occurs when this function is called with only one argument, stating the name of this concept and the type of the resulting value.

    1. 1.Step 1: Recognise that in functional programming, a function taking multiple arguments is treated as a sequence of functions taking one argument each (currying).
    2. 2.Step 2: Apply the single argument to the first type in the signature: 'Int -> (Int -> Int)'. The first 'Int' is consumed.
    3. 3.Step 3: Identify the resulting construct: a new function waiting for the remaining argument, with type 'Int -> Int'.
    4. 4.Step 4: State the formal functional programming term for this process.
    Final Answer: The concept is partial function application (derived from currying). Providing one integer argument returns a new function of type 'Int -> Int' that awaits the second integer to produce the final integer result.
    Active Recall Memory Test
    What is the domain of a function in functional type notation?
    Key Fact: The domain is the set of all permissible input values to the function.
    What three properties make a function a 'first-class object'?
    Key Fact: It can be assigned to a variable/data structure, passed as an argument to another function, and returned as a result from a function.
    What does a type signature of '(a -> Bool) -> [a] -> [a]' describe?
    Key Fact: The higher-order function 'filter', which takes a predicate function and a list, returning a filtered list of the same element type.
    How does partial function application differ from complete function evaluation?
    Key Fact: Partial application supplies fewer arguments than required, returning a new function with a reduced type signature rather than a final result value.
    Frequently Asked Questions
    What is the difference between domain and co-domain in A-Level Computer Science?
    The domain is the set of input values for which the function is defined. The co-domain is the declared set of all possible output values that the function could produce. For example, in 'isEven : Int -> Bool', 'Int' is the domain and 'Bool' is the co-domain.
    Why do functional type signatures have multiple arrows like Int -> Int -> Int?
    Functional programming languages use currying, meaning every function strictly takes only one argument at a time. A signature like 'Int -> Int -> Int' is bracketed as 'Int -> (Int -> Int)'. It takes one integer and returns a brand-new function that takes another integer to produce the final integer.
    What makes a function a higher-order function?
    A function is considered higher-order if it does at least one of two things: it accepts another function as an argument, or it returns a function as its output. Classic examples in the AQA syllabus are 'map', 'filter', and 'fold'.
    What is the difference between a co-domain and a range?
    The co-domain is the entire set from which outputs can be drawn (e.g. all Integers), whereas the range (or image) is the actual subset of values that the function realistically outputs. If a function squares an integer, the co-domain might be all Integers, but the range is solely non-negative integers.
    Can user-defined functions be used as function types in AQA exams?
    Yes. Type signatures can include custom data types such as 'Person -> String' or 'Tree -> Int'. The arrow operator functions identically regardless of whether the types involved are built-in primitives or custom user-defined data structures.