Next: , Up: Semantics   [Contents]


3.1 Introduction to declarative programming

Declarative programming is concerned with the idea of “truth”. For example, it’s true that 1 plus 1 is 2, and that the length of the list [1, 2, 3] is 3. Statements like this that may be either true or false are known as propositions, e.g., 1 + 1 = 2 and 1 + 2 = 5 are both propositions; if + is interpreted as integer addition then the first proposition is true and the second is false.

While programming languages that fit withim the functional programming or logic programming paradigms are typically considered “declarative”, there is no agreed upon definition of the term. One notable characteristic of declarative languages, however, is that they have both a declarative and an operational semantics.

The operational semantics defines how programs should be executed by the system; programming languages generally provide an operational semantics. A declarative semantics is not generally provided, and yet is conceptually simpler as it is only concerned with what is true about the inputs and outputs of code, and not the details of execution. This is often expressed by saying that the declarative semantics is about “what” whereas the operational semantics is about “how”.

The advantage of having a declarative semantics in addition to an operational semantics is that, despite its relative simplicity, it can be very effective in analysing the correctness of code. For deeper analyses, the operational semantics can still be used.