Log in / create account | Login with OpenID
DocForge
An Open Wiki For Software Developers

Declarative programming language

From DocForge

A declarative programming language is a high-level programming 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".

Declarative programming languages can be declarative in a variety of ways. Logic programming languages, such as Prolog, are 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 and regular expressions are examples).

There are a number of completely declarative languages. Examples include interface description languages (IDLs), which are often declarative, as they specify relationships without specifying computation. Other examples include frame languages, and ontology languages, such as OWL and CycL, which are used to encode knowledge about relationships.

Purely declarative languages, in general, do not "compute" anything; rather, they specify relationships. These relationships are then commonly used to perform computation. Thus, for example, in an ontology language beased on first-order logic, the predicate isHuman(X) can be used to perform the computation that isHuman(Socrates) is true. Another example is provided by VRML, the virtual reality markup language, a 3D scene description language. In this language, a "rotating" declarative can be used to assert that an object spins. When drawn visually, the object is meant to be drawn as spinning.

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 monads (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 programming language, may have declarative aspects — static memory allocation and macros, for example.

Examples of Declarative Programming

Additional copyright notice: Some content of this page is a derivative work of a Wikipedia article under the CC-BY-SA License and/or GNU FDL. The original article and author information can be found at http://en.wikipedia.org/wiki/Declarative_programming_language.