Declarative programming language

From Wikipedia, the free encyclopedia

A declarative programming language is a high-level language that describes a problem rather than defining a solution — it makes use of declarative programming. A declarative programming language says "what", while an imperative programming language says "how". The term is not entirely clear and often controversial; it is sometimes used as a buzzword.

Declarative programming languages can be declarative in a variety of ways. Prolog is declarative in that the programmer states relationships and asks a question about those relationships — without defining how to compute the answer. Functional programming languages are declarative in that functions relate their output to their input — without defining a strict order to evaluate any operations. Data-oriented programming languages and query languages are declarative in that queries are not given in terms of how to find data but instead give criteria for the desired data (SQL is an example).

Only the oddest examples of programming languages are completely declarative. Interface description languages (IDLs) are often declarative, as they specify relationships without specifying computation. But both of these examples don't compute anything, and it is not clear that they are in fact programming languages at all.

The distinctions are never sharp; Prolog can be used to compute explicitly, by use of recursive rules and the cut operator. Functions that aren't purely functional or make use of a monad (by being in CPS or using I/O) do strictly sequence operations. SQL's INSERT and DELETE commands are dependent on sequence. On the other hand, assembly language, the lowest level of instruction sequences possible, has declarative aspects — static memory allocation and macros, for example.

[edit] Languages generally considered declarative

Category:Declarative programming languages tries to provide an exhaustive list

[edit] Examples of declarative programming in action

[edit] See also