Last modified on 27 July 2009, at 03:18

Computer Programming/Functional programming/At a glance

CharacteristicsEdit

  • First-class functions. In functional languages, functions are just data, and can be passed to and returned from other functions as desired.
  • Immutability. In functional programming, the use of mutable variables is generally "discouraged", which is to say functional languages usually make the programmer go out of her way to create a variable whose value can change, or they disallow the practice altogether. While this may sound like an onerous restriction, in practice it has essentially no impact on the programs you can comfortably express; it turns out, rather, that the choice of using mutable or immutable variables is usually a matter of efficiency.
  • Recursion. Without mutable variables, we don't write loops like
for (i=0; i<100; i:=i+1) { /* do some stuff */}

. In such cases we generally write recursive functions to do the same computation.

FeaturesEdit

Here are some typical features of functional languages

  • tuples
  • parametric polymorphism
  • type inference
  • pattern matching
  • laziness

The languagesEdit

There are many so-called functional languages. The most widely used pure functional languages (that is, ones whose programs have no side effects) are Haskell and Erlang. Other popular functional languages which are not pure in the strict sense but still support the functional programming style in its full splendor are ML, Objective Caml, Scheme and Lisp.