An Approach To Specific Declarative Computer Programming Paradigms

In this article we will explain and discuss the declarative family of the fundamental style of computer programming. Mostly, we will focus on the functional and logic computer programming paradigms.

In computer science, the functional computer programming paradigm is basically a fundamental style of computer programming that treats computation as the evaluation of mathematical functions and avoids state (in the contrast with the imperative computer programming paradigm that emphasizes changes in state) and mutable data. Computer programming languages that use the functional concept as the fundamental style of computer programming, are using as their basic model or theoretical framework for describing functions and their evaluation two existing concepts. The lambda calculus (the theoretical framework for describing functions and their evaluation) and the combinatory logic (that is a notation, commonly perceived as more abstract than the lambda calculus and basically introduced to eliminate the need for variables in the mathematical logic).

There are some well known concepts and characteristics of the functional computer programming paradigm. Iteration is in the functional style of computer programming usually accomplished via recursion. Recursive functions are calling themselves and allowing an operation to be performed over and over again. Common patterns of recursion can be factored out using higher order functions, catamorphisms (defined in the category theory, denotes the unique homomorphism for an initial algebra) and anamorphisms (that are the categorical dual of catamorphisms). Higher-order functions are functions that can take other functions as arguments, and return them as results. In the functional computer programming paradigm we also meet characteristics and concepts that make it pretty different from other fundamental styles of computer programming, like for instance the pure functions. Pure functions are functions that have no side effects. A function or expression is said to produce a side effect if it modifies some state in addition to returning a value. Computer software developers therefore do not really like to use pure functional computer programming languages, because the pure functions do not accept input, produces no output, and interfaces with no external devices. An example of a computer programming language that uses a purely functional computer programming paradigm is Haskell. It uses a strong (that is used to describe situations where computer programming languages specify one or more restrictions on how operations involving values having different data types can be intermixed) and static typing discipline, with non-strict (and delayed evaluation, that is the technique of delaying a computation until such time as the result of the computation is known to be needed) computer programming language semantics. Not all computer programming languages with the functional fundamental style of computer programming are pure. For instance, computer programming languages LISP and Erlang, that use multiple fundamental styles of computer programming. The computer programming language Haskell offers powerful new ways to encapsulate abstractions. There is a simple, basic difference between declarative (more specific, functional) and imperative computer programming paradigm. The first technique uses the concept of the “what” question and the second of the “how”. Those two concepts are simply shown by a computer software algorithm that sorts a sequence of numbers into ascending order using a standard known method.

Computer software algorithm written in the C computer programming language:

void Sort(int a[], int b, int c)
{
{
int d, e, x, y;

if (b < c)
{
e = b;
d = c;
x = a[c];

do
{
while ((e < d) && (a[e] <= x))
e = e+1;
while ((d > e) && (a[d] >= x))
d = d-1;
if (e < d)
{
y = a[e];
a[e] = a[d];
a[d] = y;
}
} while (e < d);

y = a[e];
a[e] = a[c];
a[c] = y;

Sort( a, b, e-1 );
Sort( a, e+1, c );
}
}

Computer software algorithm written in the Haskell computer programming language:

Sort [] = []
Sort(x:xs) = Sort(filter (< x) xs) ++ [x] ++ Sort(filter (>= x) xs)

Although the source software code algorithms can speak for themselves and practically show you the difference between the “what” and “how” concept of the functional and imperative computer programming paradigm, we simply just can not forget the computational theory and optimization in computer science. The mathematical science really gives the theoretical basis for the functional computer programming paradigm concepts for problem solving, but there is another issue that practically effects computer software developed in it. Usually, (for instance the computer software compiler Glasgow Haskell Compiler) software compilers translate and produce inefficient machine software code (the issue is even more visible by using computer software interpreters like for instance Hugs or GHC). I do not claim that the software compilers really need to be optimized, but for example computer software compilers like GCC (for the C computer programming language) translates source software code algorithms to better, more rational and efficient machine software code. That could be changed by a optimization or by redeveloping the computer software compiler.


(Image source from the Lemonodor HTTP server.)

The logic fundamental style of computer programming is basically the use of mathematical logic for computer programming and is a part of the declarative computer programming paradigm. Very well known is the computer programming language Prolog, developed in the year of 1972. The fact that there are alternative ways of executing a logic software algorithm has been characterized by the equation:

    Algorithm = Logic + Control

The term “Logic” represents a logic computer software and the term “Control” represents different theorem-proving strategies.

We know many different extensions of the logic computer programming paradigm. Inductive logic fundamental style of computer programming is concerned with generalizing positive and negative examples in the context of background knowledge. Concurrent constraint logic fundamental style of computer programming combines concurrent logic and constraint logic (allows some predicates, declared as constraint predicates, to occur as literals in the body of clauses), using constraints to control concurrency. The abductive logic computer programming paradigm allows some predicates, declared as abducible predicates, to be incompletely defined.

The functional logic computer programming paradigm aims to amalgamate the most important declarative computer programming paradigms, namely functional and logic computer programming fundamental styles. It has a more expressive power due to the availability of features like function inversion, partial data structures, existential variables, and non-deterministic search. It has also a more efficient operational behavior since functions provide for more efficient evaluation strategies (lazy/delayed evaluation, deterministic reductions) than predicates.

The functional and imperative computer programming paradigms are however very different. As I recently pointed out, the most visible differences are side effect functions, which are used in the imperative fundamental style of computer programming to implement the state and input/output concept. The pure functional computer programming paradigm completely disallows side effects of functions used in the computer software algorithm. Disallowing this concept for referential transparency (which are properties of parts of a computer software), which makes it pretty easier to optimize, verify and parallelize software, as well as to easier develop automated computer software to execute those tasks.

The efficiency issue of software developed in computer programming languages that use as its fundamental style of computer programming the functional orientation is not just effected because of the computer software compilers and interpreters, but also because of other conceptual issues. These computer programming languages have automatic memory management (the act of managing computer software memory) with garbage collection (which is a form of automatic memory management). In contrast, computer programming languages that use the imperative fundamental style of computer programming use explicit memory management. Why is this an issue? It is an issue, because functional computer programming languages were perceived as less efficient in their use of the central processing unit and memory. It is however not a rule. Modern computer programming languages like for instance Python, Java or Perl, that use the imperative computer programming paradigm, also perform automatic memory management. The worst case slowdown was shown to be exponential. Situations where such slowdowns arise occur very rarely in practice. Computer software compilers and interpreters of the computer programming languages Objective Caml and Clean (that also use the functional fundamental style of computer programming) produce relative efficient machine software code and execution speed of the software algorithm that could be compared to machine software code developed in the C computer programming language.

- שָׁלוֹם ולהתראות ,לוקה

Copyright © 2008 by Luka Woititz

Advertisement

2 Responses to “An Approach To Specific Declarative Computer Programming Paradigms”

  1. Many potential distractions and interruptions can occur while in the archives, but careful planning can eliminate most of these nuisances. ,

  2. My cousin would fall in love this post. We were not too long ago speaking about this. hehe

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.