Internet application development - Dariusz Harpula

Monday, February 26, 2007

Functional programming languages

Imperative programming, as contrasted with declarative programming, is a programming paradigm that describes computation as statements that change a program state. In much the same way as the imperative mood in natural languages expresses commands to take action, imperative programs are a sequence of commands for the computer to perform. A commonly used synonym to imperative programming is procedural programming.Imperative programming languages stand in contrast to other
types of languages, such as functional and logical programming languages.

Functional programming is a style of programming that emphasizes the evaluation of expressions, rather than execution of commands. The expressions in these language are formed by using functions to combine basic values. A functional language is a language that supports and encourages programming in a functional style.

Functional programming languages, especially "purely functional" ones, have largely been emphasized in academia rather than in commercial software development. However, notable functional programming languages used in industry and commercial applications include Erlang (concurrent applications),[2] R (statistics), Mathematica (symbolic math),[3] J and K (financial analysis), and domain-specific programming languages like XSLT.[4][5] Important influences on functional programming have been lambda calculus, and the programming languages APL and Lisp, and more recently ML and Haskell.

In an imperative language, one might describe an algorithm for adding values together to get a sum thus:

for (i = 0, sum = 0; i <= 100; i++ ) sum += i;

The functional equivalent would be expressed without any variable updates (e.g. operations upon whose side-effects the process depends), perhaps as:

Sum[1..100];

Major benefits of functional programming include that: *By trying to eliminate side-effects, it makes more explicit the relationship between input and output. Code is more readily understood. *Since it describes inputs and outputs rather than the detail of algorithms, more code optimizing can be readily done. This is of particular value when trying to build programs to run on parallel computing architectures.

EXAMPLES:
[F#]


Combining the efficiency, scripting, strong typing and productivity of ML with the stability, libraries, cross-language working and tools of .NET.

F# is a programming language that provides combination of type safety, performance and scripting, with all the advantages of running on a high-quality, well-supported modern runtime system. F# gives you a combination of

* interactive scripting like Python,
* the foundations for an interactive data visualization environment like MATLAB,
* the strong type inference and safety of ML,
* a cross-compiling compatible core shared with the popular OCaml language,
* a performance profile like that of C#,
* easy access to the entire range of powerful .NET libraries and database tools,
*a foundational simplicity with similar roots to Scheme,
*the option of a top-rate Visual Studio integration,
* the experience of a first-class team of language researchers with a track record of delivering high-quality implementations,
*the speed of native code execution on the concurrent, portable, and distributed .NET Framework.


F# is a pragmatically-oriented variant of ML that shares a core language with OCaml. F# programs run on top of the .NET Framework. Unlike other scripting languages it executes at or near the speed of C# and C++, making use of the performance that comes through strong typing. Unlike many statically-typed languages it also supports many dynamic language techniques, such as property discovery and reflection where needed. F# includes extensions for working across languages and for object-oriented programming, and it works seamlessly with other .NET programming languages and tools.


[OCaml]

Caml is a general-purpose programming language, designed with program safety and reliability in mind. It is very expressive, yet easy to learn and use. Caml supports functional, imperative, and object-oriented programming styles.The Caml language has been developed since 1985 at INRIA by the Formel and Cristal teams. Caml Light, which was eveloped in the early 1990s, is still in use today, especially in education. Objective Caml offers a richer programming language as well as efficient native code compilers for many architectures.

Strengths:

* A powerful type system, equipped with parametric polymorphism and type inference. For instance, the type of a collection can be parameterized by the type of its elements. This allows defining some operations over a collection independently of the type of its elements: sorting an array is one example. Furthermore, type inference allows defining such operations without having to explicitly provide the type of their parameters and result.
* User-definable algebraic data types and pattern matching. New algebraic data types can be defined as combinations of records and sums. Functions that operate over such data structures can then be defined by pattern matching, a generalized form of the well-known switch statement, which offers a clean and elegant way of simultaneously examining and naming data.
* Automatic memory management, thanks to a fast, unobtrusive, incremental garbage collector.
* Separate compilation of stand-alone applications. Portable bytecode compilers allow creating stand-alone applications out of Caml Light or Objective Caml programs. A foreign function interface allows Caml code to interoperate with C code when necessary. Interactive use of Caml is also supported via a “read-evaluate-print” loop.
* A sophisticated module system, which allows organizing modules hierarchically and parameterizing a module over a number of other modules.
* An expressive object-oriented layer, featuring multiple inheritance and parametric classes.
* Efficient native code compilers. In addition to its bytecode compiler, Objective Caml offers a compiler that produces efficient machine code for many architectures.




F# compared with OCaml

Feature

F#

OCaml

Unicode strings and wide chars

Yes


Functions as values

Yes

Yes

Discriminated unions

Yes

Yes

Generics/
Type parameters

Yes

Yes

"Interior" bindings

Yes

Yes

Records

Yes

Yes

Pattern matching

Yes

Yes

Type aliases

Yes

Yes

Modules

Yes

Yes

Module Signatures

Yes

Yes

Nested Modules

Yes

Yes

Namespaces

Yes


Strong-named assemblies

Yes


Inheritance (authoring)

Yes

Yes

Object expressions

Yes

Yes

Structural subtyping constraints


Yes

Nominal subtyping constraints

Yes


Structured classes


Yes

Variance on type parameters


Yes

Labelled Arguments


Yes

Default parameters


Yes

"Printf" style formatting

Yes

Yes

Operator Overloading

Yes


Functors


Yes








References:
http://www.cbbrowne.com/info/functional.html
http://en.wikipedia.org/wiki/Imperative_programming
http://en.wikipedia.org/wiki/Functional_programming
http://research.microsoft.com/fsharp/language-compare.aspx
http://research.microsoft.com/fsharp/fsharp.aspx

Labels:

0 Comments:

Post a Comment

<< Home