Functional Programming Paradigm
A Functional Programming Paradigm is a declarative programming paradigm that emphasizes the evaluation of mathematical functions and avoids state and mutable data.
- Context:
- It can be adhered to by a Functional Software Program (with functional programming code).
- It can be adhered to by a Functional Programming Language.
- …
- Counter-Example(s):
- See: Declarative Programming, Expression (Computer Science), Side Effect (Computer Science), Lambda Calculus.
References
2015
- (Wadler, 2015) ⇒ Philip Wadler. (2015). “Propositions As Types.” In: Communications of the ACM Journal, 58(12). doi:10.1145/2699407
- Propositions as Types observes a deep correspondence between logic and computation: propositions in a logic correspond to types in programming language; proofs of propositions corresponse to programs of the corresponding type; and simplification of proofs corresponds to evaluation of programs.
- Propositions as Types is broadly applicable, applying to a wide variety of logics (intuitionistic, second-order classical, linear) and of language features ([lambda calculus parametric polymorphism]], continuations, concurrency).
- Often the same ideas are discovered independently by logicians and computer scientists, demonstrating some asepects of programming language design are not arbitrary but absolute.
2014
- (Wikipedia, 2014) ⇒ http://en.wikipedia.org/wiki/functional_programming Retrieved:2014-7-12.
- In computer science, functional programming is a programming paradigm, a style of building the structure and elements of computer programs, that treats computation as the evaluation of mathematical functions and avoids state and mutable data. Functional programming emphasizes functions that produce results that depend only on their inputs and not on the program state — i.e. pure mathematical functions. It is a declarative programming paradigm, which means programming is done with expressions. In functional code, the output value of a function depends only on the arguments that are input to the function, so calling a function f twice with the same value for an argument x will produce the same result f(x) both times. Eliminating side effects, i.e. changes in state that do not depend on the function inputs, can make it much easier to understand and predict the behavior of a program, which is one of the key motivations for the development of functional programming.
Functional programming has its roots in lambda calculus, a formal system developed in the 1930s to investigate computability, the Entscheidungsproblem, function definition, function application, and recursion. Many functional programming languages can be viewed as elaborations on the lambda calculus. In the other well known declarative programming paradigm, logic programming, relations are at the base of respective languages.
In contrast, imperative programming changes state with commands in the source language, the most simple example is the assignment. Functions do exist, not in the mathematical sense, but in the sense of subroutine. They can have side effects that may change the value of program state. Functions without return value therefore make sense. Because of this, they lack referential transparency, i.e. the same language expression can result in different values at different times depending on the state of the executing program.
Functional programming languages, especially purely functional ones such as Hope and Rex, have largely been emphasized in academia rather than in commercial software development. However, prominent functional programming languages such as Common Lisp, Scheme, Clojure, Racket, Erlang, OCaml, Haskell, and F#[1] [2] have been used in industrial and commercial applications by a wide variety of organizations. Functional programming is also supported in some domain-specific programming languages like R (statistics), Mathematica (symbolic and numeric math), J, K and Q from Kx Systems (financial analysis), XQuery/XSLT (XML), and Opal.[3] Widespread domain-specific declarative languages like SQL and Lex/Yacc use some elements of functional programming, especially in eschewing mutable values.
Programming in a functional style can also be accomplished in languages that aren't specifically designed for functional programming. For example, the imperative Perl programming language has been the subject of a book describing how to apply functional programming concepts. C# 3.0 and Java 8 added constructs to facilitate the functional style. An interesting case is that of Scala - it is frequently written in a functional style, but the presence of side effects and mutable state place it in a grey area between imperative and functional languages.
- In computer science, functional programming is a programming paradigm, a style of building the structure and elements of computer programs, that treats computation as the evaluation of mathematical functions and avoids state and mutable data. Functional programming emphasizes functions that produce results that depend only on their inputs and not on the program state — i.e. pure mathematical functions. It is a declarative programming paradigm, which means programming is done with expressions. In functional code, the output value of a function depends only on the arguments that are input to the function, so calling a function f twice with the same value for an argument x will produce the same result f(x) both times. Eliminating side effects, i.e. changes in state that do not depend on the function inputs, can make it much easier to understand and predict the behavior of a program, which is one of the key motivations for the development of functional programming.
- (Meijer, 2014) ⇒ Erik Meijer. (2014). “The Curse of the Excluded Middle].” In: Queue Journal, 12(4). doi:10.1145/2611429.2611829
- QUOTE: Imperative programs describe computations by repeatedly performing implicit effects on a shared global state. In a parallel/concurrent/distributed world, however, a single global state is an unacceptable bottleneck, so the foundational assumption of imperative programming that underpins most contemporary programming languages is starting to crumble. Contrary to popular belief, making state variables immutable comes nowhere close to eliminating unacceptable implicit imperative effects. Operations as ordinary as exception operation\exceptions, threading, and I/O cause as much hardship as simple mutable state. …
… Pure functional programming is programming with mathematical functions. This means the only way to express dependencies among values is by applying functions to arguments and harvesting values returned. Calling a function with the same arguments will return the same result every time.
- QUOTE: Imperative programs describe computations by repeatedly performing implicit effects on a shared global state. In a parallel/concurrent/distributed world, however, a single global state is an unacceptable bottleneck, so the foundational assumption of imperative programming that underpins most contemporary programming languages is starting to crumble. Contrary to popular belief, making state variables immutable comes nowhere close to eliminating unacceptable implicit imperative effects. Operations as ordinary as exception operation\exceptions, threading, and I/O cause as much hardship as simple mutable state. …
1999
- http://eprints.eemcs.utwente.nl/1077/03/introduction.html
- C functional random
int functional_random( int seed ) { return 22 * seed % 37 ; }
- C using functional random
int first = functional_random( 1 ) ;
int second = functional_random( first ) ;
int third = functional_random( second ) ; - C imperative random
int seed = 1 ;
int imperative_random( void ) {
seed = 22 * seed % 37 ;
return seed ;}
- C functional random