Computer Programming/Functional programming/At a glance

Characteristics edit

  • 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.

Features edit

Here are some typical features of functional languages

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

The languages edit

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.