Advanced

Functional Programming Paradigm

AicademyAicademy
·A-Level Computer Science·AQA 7517·5 min
4.12.1 Functional programming paradigm

Functions as Mathematical Mappings

In functional programming, a function is a mathematical mapping from an input set to an output set.

  • is the domain — the set of all valid inputs (the input type)
  • is the co-domain — the set of all possible outputs (the output type)

Worked examples:

FunctionNotationMeaning
Integer additionTakes two integers; returns an integer
String lengthTakes a string; returns a natural number (non-negative integer)
Even predicateTakes an integer; returns a Boolean

The notation specifies the function's type. For a function to be composable with another, the types must be compatible.

Multi-argument functions: modelled as functions of a Cartesian product:

This takes a pair from the Cartesian product and maps it to an element of .

First-Class Functions

In functional programming, functions are first-class objects — they can be used anywhere any other value can be used:

  1. Assigned to a variable:
    double = \x -> x * 2
    
  2. Passed as an argument to another function:
    map double [1, 2, 3]  -- applies double to every element
    
  3. Returned from a function:
    makeAdder n = \x -> x + n
    add5 = makeAdder 5
    add5 10  -- returns 15
    
  4. Stored in data structures:
    operations = [double, (+1), (*3)]
    

Treating functions as first-class values enables the higher-order function patterns (map, filter, fold) that make functional programming expressive.

Function Application

Function application is the act of applying a function to its argument(s).

Examples:

square 5         -- evaluates to 25
not True         -- evaluates to False
length "hello"   -- evaluates to 5

Multi-argument application:

add 3 4    -- evaluates to 7

In Haskell, multi-argument functions are applied one argument at a time (currying). add 3 4 is (add 3) 4 — first apply add to 3, getting a function, then apply that function to 4.

Partial Function Application

Partial function application applies a function to fewer arguments than it expects, producing a new function that takes the remaining arguments.

Type signature:

This reads: add takes an integer and returns a function from integer to integer. In other words, the arrow groups right-to-left: .

Partial application example:

add : integer -> integer -> integer
add 4 : integer -> integer   -- partially applied: add 4 returns a new function
add 4 6 = 10                 -- fully applied

add 4 is a function that adds 4 to any integer. It can be passed to map:

map (add 4) [1, 2, 3]   -- evaluates to [5, 6, 7]

This is the power of partial application: specifying some arguments now and the rest later, creating specialised functions from general ones.

Something not quite clicking?

Ask Aica to explain any part of this differently. Free, takes 30 seconds.

Ask Aica

Function Composition

Function composition combines two functions into a single function, applying one after the other.

Key constraint: the co-domain of must equal the domain of . The output type of must be the input type of .

Worked example:

Let be length (maps strings to integers) and be isEven (maps integers to booleans).

lengthIsEven = isEven . length   -- composition in Haskell uses (.)
lengthIsEven "hello"             -- False
lengthIsEven "hi"                -- True

Why composition matters: it allows building complex transformations from simple, tested functions — a core principle of functional programming.

Common Exam Mistakes

1. Confusing domain and co-domain

The domain is the input type (what the function accepts). The co-domain is the output type (what it returns). — A is the domain, B is the co-domain. Swapping them in type notation is a common error.

2. Confusing function application with function definition

square 5 is applying the function square to the value 5 — it evaluates to 25. It is not defining a function called square 5. Function application produces a value; function definition creates a function.

3. Misreading the arrow notation for partial application

does not mean add takes two separate arguments simultaneously. It means add takes one integer and returns a function . The arrow is right-associative.

4. Applying composition in the wrong order

is applied first, then . Reading left-to-right, appears first — but it is applied second. The rightmost function in the composition chain runs first.

Generate revision on any topic you study

Type any topic you're studying and Aicademy generates a complete lesson, quiz, and flashcard set — personalised to your level.

Lessons on anything

Structured, level-matched lessons on any topic you study

Practice quizzes

Find out what you actually know before the exam does

Flashcard sets

Lock in key concepts with instant revision cards

Ask Aica

Stuck on something? Get a clear explanation, any time

Next

Functional Programming in Practice

Related lessons

7 Slides

Lesson

Functional Programming in Practice

A-Level Computer Science · AQA 7517

10 hours ago

6 Slides

Lesson

Big Data

A-Level Computer Science · AQA 7517

10 hours ago