Functional programming

Revision as of 10:32, 21 July 2008 by rosettacode>Dmitry-kazakov (Created)

Functional programming is a programming paradigm that abstracts away the computation state. The program is designed in a stateless, and thus immutable, manner. In this sense functional programming opposes imperative programming, which focuses on state transitions. Functional programming uses procedural decomposition (see procedural programming) and closures. Subprograms there are pure functions, with the only side effect allowed on the function result. Iteration is typically replaced by recursion, as the former exposes the state either in the form of the loop variable or as the exit condition.

Stateless abstraction ease program semantics definition. In particular it removes the problems with:

  • the order of subexpression evaluation,
  • aliasing,
  • the evaluation time (see lazy evaluation).

At the same time it makes programming considerably more difficult, especially when the notion of state is natural to the domain space. Functional languages like Haskell provide some support for stateful programming, see monads.