| Characteristic | What it means for the programmer |
|---|---|
| Specification of logic (AO1) | Code expresses relationships, constraints or transformations instead of step‑by‑step commands. |
| Implicit control flow (AO1) | Loops, recursion, back‑tracking, or lazy evaluation are performed automatically by the language system. |
| Immutability & pure functions (AO1) | Values cannot be altered after creation; a function always returns the same result for the same arguments. |
| Higher‑level abstraction (AO2) | Programs are shorter, more readable and map closely to the problem domain. |
| Evaluation strategies (AO1) | Typical strategies are lazy (demand‑driven) evaluation, eager (strict) evaluation and back‑tracking search. |
-- Haskell
evens = filter even [1..] -- infinite list, not evaluated yet
firstFive = take 5 evens -- only the first five elements are computed
% Prolog
grandparent(X,Z) :- parent(X,Y), parent(Y,Z).
| Language | Paradigm type | Typical use in the syllabus |
|---|---|---|
| SQL | Declarative query language (set‑based) | Database querying, data manipulation (AO1, AO2) |
| Prolog | Logic programming | Knowledge representation, rule‑based inference (AO1, AO2) |
| Haskell / F# / Erlang | Functional programming | Pure functions, higher‑order functions, immutability (AO1, AO2) |
| MiniZinc, CLP | Constraint programming | Modelling optimisation and satisfaction problems (AO1, AO2) |
| HTML / CSS | Markup & style (declarative description of structure & presentation) | Web page design – not examined for code writing but useful for understanding declarative description (AO1) |
| Jess / Drools | Rule‑based AI | Expert‑system style reasoning (AO1, AO2) |
| Advantages | Limitations |
|---|---|
|
|
SELECT name FROM Students WHERE grade > 80;ancestor(X,Y) :- parent(X,Z), ancestor(Z,Y).sumSquares xs = sum (map (^2) xs)SELECT … FROM … WHERE … → Declarative (SQL).:- → Declarative (Logic programming).SELECT name
FROM Students
WHERE subject = 'Mathematics' AND score > 80;
Marking guide (AO1‑AO2): identify the language (SQL), describe what the query does, and note that the DBMS decides the access path (indexes, joins).
grandparent(X,Z) :- parent(X,Y), parent(Y,Z).
Marking guide: recognise the rule syntax, explain back‑tracking through parent facts, and state that the interpreter searches for bindings that satisfy both sub‑goals.
evens = filter even [1..] -- infinite list, not evaluated yet
firstFive = take 5 evens -- only the first five elements are forced
Marking guide: identify lazy evaluation, describe how only the needed part of the infinite list is computed.
int: n = 3; % three tasks
array[1..n] of var 1..n: start; % start time of each task
constraint forall(i in 1..n-1) (start[i] < start[i+1]); % tasks must be ordered
solve satisfy;
Marking guide: recognise the constraint model, explain that the solver searches for values of start satisfying the ordering constraint.
| Aspect | Declarative | Imperative |
|---|---|---|
| Focus | What the result should be | How to compute the result |
| Control flow | Implicit (handled by language runtime) | Explicit (loops, conditionals) |
| State | Immutable, pure functions where possible | Mutable variables and side‑effects common |
| Typical problems | Database queries, logical inference, constraint solving | Algorithmic loops, low‑level I/O, real‑time control |
| Debugging | Harder to trace hidden execution order | Straightforward step‑by‑step tracing |
The declarative paradigm shifts the programmer’s role from giving explicit step‑by‑step instructions to specifying the desired outcome. By abstracting control flow, state management and optimisation, declarative languages provide concise, readable solutions for domains such as database querying, logical inference, constraint solving and functional computation. Mastery of the characteristics, typical languages, evaluation strategies, advantages, limitations and exam‑style tasks enables students to select the most appropriate paradigm for a given problem and to answer Cambridge AS & A Level Computer Science (9618) questions with confidence.
Create an account or Login to take a Quiz
Log in to suggest improvements to this note.
Your generous donation helps us continue providing free Cambridge IGCSE & A-Level resources, past papers, syllabus notes, revision questions, and high-quality online tutoring to students across Kenya.