Home >> Computers >> Programming >> Compilers >> Functional


  Erlang
Haskell
  Lisp
Poplog
  Scheme


Functional programming occurs as programming paradigm that treats computation as the evaluation of mathematical functions. These are extra heavy utilized around academe than within industry. the nature and severity of a functional paradigm is the removal of side-results when you took computation. This has uses around two program verification, for checking a correctness of computer software, & around program optimization. A single particular have around program optimization is to transform software online for parallel programming.

Functional programming emphasizes a definition of functions, like than a implementation of state machines. This is around direct contrast to procedural or imperative programming where programming emphasizes the sequencing of commands within execution. A values around these languages come formed by applying assignments to transform a state of the program. The functional program is changeless: like than modify state to make values, it constructs state from either older pieces of state in the program.

Introduction

Mathematical functions have great strengths around terms of flexibility & analysis. For instance, whenever the work is known to exist as idempotent, then the call for to the work which hwhen its stand output as its argument, & which is known to have there are no side-effects, may be expeditiously computed forgoing multiple calls.

The work in that feel has zero or even further parameters & one link to value. A parameters—or even arguments, when it is another time known as—come a inputs to a work, & the go to value is the work's output. a definition of a work describes how else the work is to exist as evaluated inside terms of more functions. For instance, a work f(x) = xDeuce + Two is defined around terms of the power & addition functions. At a few point, a language has to provide basic functions that involve there is no farther definition.

Functions may be manipulated around the kind of ways within the functional programing language. Functions come treated when first-class values, which is to say that functions may be parameters or even even inputs to more functions & can be the link to values or outputs of a work. This allows functions rather mapcar inside LISP and map in Haskell that take two a work & the listings when input & use the input work to each element of the names. Functions may be known when, as around more languages, or even defined anonymously (another time in the period of program execution) applying the lambda abstraction, and utilized when values inside more functions.

Functional languages too allow functions to exist as curried. Currying occurs as system of rewriting the work by owning multiple parameters as a work by having 1 parameter that maps to an additional work of of these parameter and then in, until everthing parameters come exhausted. the curried work may be applied to only a subset of its parameters. A symptom occurs when work in which a parameters therein subset come today fixed as constants, & a values of the rest of the parameters come however unspecified. This recently work may be applied to a odd parameters for the final work value. E.g., the work add(x,y) = ten + y may be curried sol that a link to value of add(Ii)—notice that no y parameter—is an anon. work that is same to the work add2(y) = Ii + y. This freshly work has lof these one parameter & corresponds to adding Deuce to the total. Over again, this is conceivable just because functions come treated when number 1-class values.

History

Lambda calculus could exist as considered the 1st functional programing language, though it was nin designed to be executed on the computer. Lambda calculus occurs as model of computation designed by Alonzo Church in the 1930s that provides the super formal way to describe work evaluation. A number 1 computer-depending functional programing language was Information Processing Language (IPL), developed by Newell, Shaw, and Simon at RAND Corporation for the JOHNNIAC computer in the mid 1950s. The lot-improved functional programing language was LISP, developed by John McCarthy while at the Massachusetts Institute of Technology for the IBM 700/7000 series scientific computers in the late 1950s. Spell non the strictly functional programing language, LISP did introduce virtually all of the features nowadays detected inside modern functional programing language. Scheme was a late attempt to simplify & improve LISP. In the 1970s the language ML was created at the University of Edinburgh, and David Turner developed the language Miranda at the University of Kent. A language Haskell was released in the late 1980s around an attempt to gather together many ideas in functional programming search.

Comparison with imperative programming

Functional programming may be contrasted sustaining imperative programming. Functional programming appears to exist as missing many constructs typically (though incorrectly) considered necessity to an imperative language like C or Pascal. E.g., within nonindulgent functional programming, there are no expressed memory allocation & no expressed variable assignment. Notwithstanding, these operations occur automatically whenever a work is invoked; memory allocation occurs to produce space for a parameters & a go to value, & assignment occurs to copy a parameters into this new allocated space & to copy the go to value back into the vocation work. Two operations potty lone occur in work entry & exit, thus side results of work evaluation come eliminated. By disallowing side results within functions, a language will bring referential transparency. This ensures that the effect of a work is the equivalent for even a given placed of parameters disregarding in which, or whilst, these are evaluated. Referential transparency greatly eases two a project of proving program correctness and the project of automatically identifying independent computations for parallel execution.

Looping, an additional imperative programming conception, is accomplished through the additional general functional construct of recursion. Recursive functions invoke themselves, allowing an operation to become performed time and time again. In point of fact, it may be proven that looping is same to the favorite nature and severity of recursion known as tail recursion. Recursion inside functional programming could require numbers of forms & is in the main the further mighty system than looping. For this understanding, about totally imperative languages besides trend lines it (by owning FORTRAN 77 and COBOL, before 2002, when notable exceptions).

Functional programming languages

Pure functional programs require no variables and have no side-effects, and are therefore automatically thread-safe. It is too automatically verifiable provided that any recursive period finally blocks. Nested functions just pass their results back to the independent work. Functional languages usually produce quite sophisticated utilise of the stack.

Functional programming typically depends heavy in recursion. A Scheme programming language even requires certain types of recursion (tail recursion) to be recognized & automatically optimized by the compiler.

What is more, functional programing language are belike to enforce referential transparency, which is the familiar notion that 'match may be substituted for equals': in case 2 expressions come defined to keep close at hand equal values, so of these may be substituted for a more in any big expression forswearing affecting the symptom of the computation. For instance, in

z = f(sqrt(Two), sqrt(Two));

i potty factor sqrt(2) & write

s = sqrt(Two); z = f(s, s);

so eliminating a additional evaluation of the square-root work.

When intuitive when it sounds, this is non universally a out break using imperative languages. The pack within point is the C programming language's getchar() "function", which gets the character from the standard input; it is strictly the work non of its arguments however of the contents of the input stream stdin you said it good deal has already been scan. As a result a lesson above:

z = f(getchar(), getchar());

i just can not eliminate getchar() when i did for sqrt(Deuce), because within C, getchar() may go to ii different values them days these are known as.

Hidden side-results come generally a rule, like than a exception, of traditional imperative programing language. When a procedure reads the value from either or even even writes the value to the spherical or divided up variable, the expected is for hidden side-results. This escape of data through procedure boundaries, withwithin ways that are non explicitly represented by work calls & definitions, greatly increases a hidden complexness of software written in conventional non-functional languages.

By removing these hidden facts leaks, functional programing language offer a possibility of great deal cleaner computer program which are then more leisurely to project & debug. Notwithstanding, it likewise offer more advantages.

Numbers of computer programmer accustomed to the imperative paradigm locate it hard to study functional programming, which encompasses a completely different way of composing software download. This difficulty, along by having a fact that functional programming environments don't keep close at h& a extensive information and libraries available for traditional programing language, come among a independent reasons that functional programming has received little utilise in the software industry. Functional languages keep around remained largely a domain of academics & hobbyists, and what little inroads use been mass produced come due to impure functional languages like Erlang and Common Lisp. It can be argued that a big influence of functional programming within a computer software industry has been by people academically trained coder world health organization keep close at hand never to return on to use the impure functional programming style to their function in traditional imperative languages.

Higher-order functions

The right mechanism for instance utilized within functional programming is the notion of higher-order functions. Functions come higher-choose whilst it might require more functions when arguments, and/or go to functions when final result. (A differential operator in calculus is the common case of the work that maps the work to a work.)

Higher-the correct sequence functions were exposed in the lambda calculus theory well prior to the notion of functional programming existed & come present in the project of a total of functional programing language, like Scheme and Haskell.

Further typically, higher choose functions can exist as said to be the a portion of natural language. E.g., adverbs might modify verbs (actions) produce to derived verbs. As a pattern of thought, imperative verbs come similar to "ordinary" functions inside programing language.

Higher-sequentially functions come important in the function-level programming paradigm, which includes languages such as John Backus's FP and Kenneth E. Iverson's J.

Speed and space considerations

Functional languages use hanker been criticised when resource-hungry, two around terms of CPU resources and memory. This was in the main due to deuce items: a bit of early functional languages were implemented using there are no concern for efficiency non-functional languages achieved speed at least inside a share by allowing retired features like bounds checking or garbage collection which are viewed as essential area of modern computing frameworks, a overhead of which was built-inherent to functional languages by default

When modern imperative languages & their implementations use began to include greater emphasis in correctness, like than raw speed, & a implementations of functional languages keep around begun to emphasize speed besides when correctness, a performance of functional languages & imperative languages has begun to converge. For software download which spend virtually all of their period doing numerical computations, occasionally functional languages (like OCaml and Clean) can approach C speed, while for computer program that cover big matrices & multidimensional databases, array functional languages (such as J and K) are unremarkably quicker than virtually all non-optimized C software. Notwithstanding, strictly functional languages may be substantially slower after manipulating big information structures, due to less effective memory usage.

Memory usage may exist as improved within functional programming by applying lasting information structures; these information structures allow section or even tons of their information to be shared sustaining more values, making copying & modifying comparatively cheap. This may be done safely because these information structures come changeless, thus a common problems by owning pointer aliasing inside imperative information structures don't arise. Among a normally utilized lasting information structures come linked lists & binary trees.

There are deuce methods of evaluating functional languages, nonindulgent (or even eager) and lazy evaluation. Nonindulgent languages evaluate everthing work arguments prior to evaluating a work itself, while sleeping languages simply evaluate the two when it is needed. Haskell is the most common lesson of the sleeping language, when Cc is nonindulgent. Sleeping evaluation potty add important performance overhead keeping track of unevaluated functions; even so, it makes programming more comfortable within numerous ways.

A competitory performance of modern (impure) functional programing language like OCaml & MLton-compiled SML has resulted around their adoption in conventionally Fortran-dominated areas of scientific computation. Thanks to the brevity, expressiveness & accessibility of sophisticated information structures & algorithmic program, modern languages come currently utilized within the wide range of scientific applications, from either numerical analysis to visual image.

Functional languages

the oldest lesson of a functional language is Lisp, though neither the original LISP nor modern Lisps like Common Lisp are pure-functional. Lisp variants include Logo, Scheme, Dylan. A modern canonical examples come Haskell and members of the ML family including SML and OCaml. Others include Erlang, Clean, and Miranda. The third nature and severity of the normally utilized functional language is Xslt.

More machine language, e.g. Tcl, Perl, Python & Ruby, can also be used in a functional style, since they have higher-order functions, abstractions and such.

Efforts come afoot to get quantum functional programing language, to express quantum algorithmic rule, & more a development of this field. Examples one come Peter Selinger's influential QPL, described inside his paper [http://scholar.google.com/scholar?hl=en&lr=&q=cache:0bfAXyE4QawJ:www.tcs.informatik.uni-muenchen.de/lehre/SS03/Quanten/papers/sel02.pdf.gz+ Towards a quantum programming language], & a Haskell-prefer language [http://www.cs.nott.ac.uk/~jjg/qml.html QML].

:Category:Functional languages provides an exhaustive listing.


Computers: Programming: Languages: Compiled: Functional
Computers: Programming: Languages: Functional
Computers: Programming: Languages: Garbage Collected
Computers: Programming: Languages: Interpreted: Functional





© 2005 GeneralAnswers.org