Functional programming: Difference between revisions

From Citizendium
Jump to navigation Jump to search
imported>Eric Evers
mNo edit summary
mNo edit summary
 
(4 intermediate revisions by 4 users not shown)
Line 1: Line 1:
==Functional programming, time and state==
{{subpages}}
{{TOC|right}}
A '''functional programming''' language is a language modeled after mathematical functions.  Non-functional computer programs allow  state changes.


A functional programming language is a language modeled after mathematical functions. Non-functional computer programs allow
==First class data types==
state changes. State changes are represented by changes in the
values of variables over time. In strict functional programming
languages variables are not allowed to change during a single
invocation of a function.


In strict functional programming state is not saved
Functional programs typically make functions first class data types. This
outside of function calls. By removing state outside of functions,
allows functions to be passes as arguments to other functions and
side effects are controled.
allows for the creation of higher order functions(functions of functions).


State may not change during a function call. Fixed state allows
==Input/Output==
for the control of side effects(bad distant changes caused by local changes). When state is fixed, functions can be treated similar to
 
In functional programming state is not saved
outside of function calls due to restrictions on  input/output calls (I/O)
State may not change during a function call. Restricting I/O
protects against side effects, such as bad distant changes I/O caused by local computation .
 
==Single assignment and proofs==
Single assignment makes a computation into a dataflow. Dataflows are easy for
compilers to understand. When state is fixed, functions can be treated similar to
mathematical functions and facts can be proved about such functions.
mathematical functions and facts can be proved about such functions.
Some functional programs can be proved to be equal to each other or
Some functional programs can be proved to be equal to each other or
proved to be stable under certain conditions. Such proofs can aid
proved to be stable under certain conditions. Such proofs can aid
the efforts of software engineers and computer scientists.  
the efforts of software engineers and computer scientists. <ref>{{citation
See (Hutton, 1999) for an example.
| author =  Graham Hutton, 1999
 
| url = http://www.cs.nott.ac.uk/~gmh/fold.pdf  
Ref 1: Graham Hutton, 1999, [http://www.cs.nott.ac.uk/~gmh/fold.pdf]
| title =  A tutorial on the universality and expressiveness of fold
      A tutorial on the universality and expressiveness of fold
  | journal = J. Functional Programming | volume = 9 | issue = 4 | pages =355–372 | date = July 1999}}</ref>
      J. Functional Programming 9 (4): 355–372, July 1999,   
      Cambridge University Press.
 
Some examples of functional programming languages are:
Some examples of functional programming languages are:
[[scheme_programming_language|scheme]],  
*[[scheme_programming_language|Scheme]],  
[[erlang_programming_language|erlang]], (excluding all parallel functions)
*[[erlang_programming_language|Erlang]], (excluding all parallel functions)
[[haskel_programming_language|haskel]].
*[[haskell_programming_language|Haskell]].
   
   
If a functional language is eager then all values are fully computed in the order that they are encountered. In a lazy language like [[haskel]]
If a functional language is eager then all values are fully computed in the order that they are encountered. In a lazy language like Haskell
some arguments are allowed to have delayed evaluation.
some arguments are allowed to have delayed evaluation.
==References==
{{reflist}}[[Category:Suggestion Bot Tag]]

Latest revision as of 11:02, 19 August 2024

This article is a stub and thus not approved.
Main Article
Discussion
Definition [?]
Related Articles  [?]
Bibliography  [?]
External Links  [?]
Citable Version  [?]
 
This editable Main Article is under development and subject to a disclaimer.

A functional programming language is a language modeled after mathematical functions. Non-functional computer programs allow state changes.

First class data types

Functional programs typically make functions first class data types. This allows functions to be passes as arguments to other functions and allows for the creation of higher order functions(functions of functions).

Input/Output

In functional programming state is not saved outside of function calls due to restrictions on input/output calls (I/O) State may not change during a function call. Restricting I/O protects against side effects, such as bad distant changes I/O caused by local computation .

Single assignment and proofs

Single assignment makes a computation into a dataflow. Dataflows are easy for compilers to understand. When state is fixed, functions can be treated similar to mathematical functions and facts can be proved about such functions. Some functional programs can be proved to be equal to each other or proved to be stable under certain conditions. Such proofs can aid the efforts of software engineers and computer scientists. [1] Some examples of functional programming languages are:

If a functional language is eager then all values are fully computed in the order that they are encountered. In a lazy language like Haskell some arguments are allowed to have delayed evaluation.

References

  1. Graham Hutton, 1999 (July 1999), "A tutorial on the universality and expressiveness of fold", J. Functional Programming 9 (4): 355–372