Functional Programming Paradigm
A Functional Programming Paradigm is a declarative programming paradigm that emphasizes the evaluation of pure functions and avoids state and mutable data.
- Context:
- It can be followed to create a Functional Software Program with functional programming code that promotes immutability and first-class functions.
- It can be implemented using a Functional Programming Language, which often enforcing constraints that prevent side-effects.
- It can lead to easier concurrency and parallel programming by avoiding mutable state and utilizing lazy evaluation techniques.
- It can be advantageous in scenarios where a Deterministic System is required, as the absence of side-effects ensures consistent outputs for given inputs.
- It can be challenging to apply in domains requiring high interaction with external systems where mutable state is unavoidable.
- ...
- Example(s):
- As followed by a Map-Reduce Algorithm that showcases the use of higher-order functions to process collections of data in parallel.
- As followed by Reactive Programming model that demonstrates how functional programming principles can be applied to handle asynchronous data streams effectively.
- …
- Counter-Example(s):
- See: Declarative Programming, Expression (Computer Science), Side Effect (Computer Science), Lambda Calculus, Higher-Order Functions.
References
2023
- (Wikipedia, 2023) ⇒ https://en.wikipedia.org/wiki/Functional_programming Retrieved:2023-5-28.
- In computer science, functional programming is a programming paradigm where programs are constructed by applying and composing functions. It is a declarative programming paradigm in which function definitions are trees of expressions that map values to other values, rather than a sequence of imperative statements which update the running state of the program.
In functional programming, functions are treated as first-class citizens, meaning that they can be bound to names (including local identifiers), passed as arguments, and returned from other functions, just as any other data type can. This allows programs to be written in a declarative and composable style, where small functions are combined in a modular manner.
Functional programming is sometimes treated as synonymous with purely functional programming, a subset of functional programming which treats all functions as deterministic mathematical functions, or pure functions. When a pure function is called with some given arguments, it will always return the same result, and cannot be affected by any mutable state or other side effects. This is in contrast with impure procedures, common in imperative programming, which can have side effects (such as modifying the program's state or taking input from a user). Proponents of purely functional programming claim that by restricting side effects, programs can have fewer bugs, be easier to debug and test, and be more suited to formal verification.[1] [2]
Functional programming has its roots in academia, evolving from the lambda calculus, a formal system of computation based only on functions. Functional programming has historically been less popular than imperative programming, but many functional languages are seeing use today in industry and education, including Common Lisp, Scheme, Clojure, Wolfram Language, Racket, Erlang, Elixir, OCaml,> Haskell,and F#. Functional programming is also key to some languages that have found success in specific domains, like JavaScript in the Web, R in statistics, J, K and Q in financial analysis, and XQuery/XSLT for XML. Domain-specific declarative languages like SQL and Lex/Yacc use some elements of functional programming, such as not allowing mutable values. In addition, many other programming languages support programming in a functional style or have implemented features from functional programming, such as C++11, C#, Kotlin, Perl, PHP, Python, Go, Rust, Raku, Scala, and Java (since Java 8).
- In computer science, functional programming is a programming paradigm where programs are constructed by applying and composing functions. It is a declarative programming paradigm in which function definitions are trees of expressions that map values to other values, rather than a sequence of imperative statements which update the running state of the program.
- ↑ Hudak, Paul (September 1989). "Conception, evolution, and application of functional programming languages" (PDF). ACM Computing Surveys. 21 (3): 359–411. doi:10.1145/72551.72554. S2CID 207637854.
- ↑ Hughes, John (1984). "Why Functional Programming Matters".
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
- (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
- (UTwente, 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