MENTAL
 Main Menu
 Applications
 Computer Science
 Declarative Programming


Declarative Programming
 DECLARATIVE
PROGRAMMING

"Say what you want, but not how you want it" (the phrase that describes declarative programming).

"The real world is not declarative. It has state (entities have internal memory) and concurrency (entities evolve independently."(Peter Van Roy & Seif Haridi)



Declarative programming vs. imperative programming

Declarative programming (also called "descriptive programming") is often contrasted with imperative programming:
Types of declarative languages

Just as there are many imperative languages, there are also many declarative languages. However, the boundary between imperative and declarative languages is fuzzy. An imperative language may include declarative resources such as functions and rules. And a declarative language can include imperative resources. It is difficult to find "pure" declarative languages.

Declarative languages are associated with one or more programming paradigms. For example:
Characteristics of declarative programming
Advantages of declarative programming

Declarative programming has several advantages over imperative programming:
MENTAL and Declarative Programming

MENTAL is a multi-paradigm language. Different paradigms can be expressed using the same linguistic resources. Some paradigms (such as the logical paradigm) are essentially declarative, but in all paradigms declarative expressions can be used, which can be of the imperative, logical, functional, algebraic, etc. type.

Declarative programming is not really a programming paradigm, but a meta-paradigm or a programming style that can be used in all programming paradigms.

It is often stated that there is a fuzzy boundary between imperative and declarative programming. With MENTAL, this issue is clarified: there is no such (horizontal) boundary, but a dyadic (vertical) relationship between declarative programming and all programming paradigms, including the imperative paradigm.

In MENTAL declarative expressions are of several types:
  1. Generic expressions. They produce inferences or automatic calculations. Thanks to generic expressions, many programming paradigms can be specified: logic programming, event-driven, constraint-driven, aspect-driven, agent-driven, etc.

  2. Deferred substitutions (representations).

  3. Substitution expressions in which relations of all kinds are established: logical, algebraic, etc.

Examples of declarative expressions
  1. ⟨( f(x y) = (x+y x*y) )⟩ // function
    f(3 4) // ev. (7 12)


  2. ⟨( m>5 → m=5 )⟩ // rule
    (m = 12) // ev. (m = 5)


  3. ( v =: a+b+c ) // representation
    (a=1 b=2 c=3)
    v // ev. 6


  4. a∈C // membership relation to a previously undefined set C
    (x = 0)
    (a∈C → (x = 123)
    x // ev. 123


  5. A⊂B // inclusion relation of one set into another, both not previously defined
    (x = 0)
    (A⊂B → (x = 123))
    x // ev. 123


  6. (a*b = c) // algebraic relation between previously undefined variables
    (x = 0)
    ((a*b = c) → (x = 123))
    x // ev. 123


  7. (ε^2 = 0) // definition of infinitesimal (imaginary expression)
    (a+ε)^2 // ev. (a^2 + 2aε)


  8. (i^2 = -1) // definition of the imaginary unit (imaginary expression)
    (a+i)^2 // ev. (a^2 + 2ai - 1)
    i^3 // ev. −i


Bibliography