Declarative Programming Techniques
Declarative programming is important because of two properties:
- Declarative programs are compositional. A declarative program consists of components that can each be written, tested, and proved correct independently of other components and of its own past history (previous calls).
- Reasoning about declarative programs is simple. Programs written in the declarative model are easier to reason about than programs written in more expressive models. Since declarative programs compute only values, simple algebraic and logical reasoning techniques can be used.
Definitions
Component
Let us define a component as a precisely delimited program fragment with well-defined inputs and outputs. A component can be defined in terms of a set of simpler components. For example, in the declarative model a procedure is one kind of component. The application program is the topmost component in a hierarchy of components. The hierarchy bottoms out in primitive components which are provided by the system.
Recursive Function Definitions
The basic technique for writing declarative programs is to consider the program as a set of recursive function definitions, using higher-order programming to simplify the program structure. A recursive function is one whose definition body refers to the function itself, either directly or indirectly. Direct recursion means that the function itself is used in the body. Indirect recursion means that the function refers to another function that directly or indirectly refers to the original function.
Higher-Order Programming
Higher-order programming means that functions can have other functions as arguments and results.
What is Declarativeness?
A Classification of Declarative Programming
The first level of classification is based on the expressiveness.
- A Descriptive Declarativeness: The least expressive.
- A Programmable Declarativeness: As expressive as a Turing Machine. there are
two fundamentally different ways to view this category.
- A Definiotional View:
- Declarative Model
- Functional Programming
- Logic Programming
- An Observational View:
- A Definiotional View: