Difference between revisions of "Pure"
m |
m |
||
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
+ | (In contrast to <i>applied</i>, when distinguishing between applied and [https://web.archive.org/web/20221204080950/https://www.maynoothuniversity.ie/mathematics-and-statistics/undergraduate-studies/why-do-research-pure-mathematics pure mathematics]; the latter being <q>divorced from the real world</q>.) |
||
− | A function is called '''pure''' if it corresponds to a function in the mathematical sense: it associates each possible input value with an output value, and does nothing else. In particular, |
||
⚫ | In mathematics, functions are <b>pure</b> - they merely associate each possible input value with an output value, and nothing more. In Haskell, most functions uphold this principle. As a result, they usually are [[Referential transparency|referentially transparent]] - each of them does not depend on anything other than its parameters, so when invoked in a different context or at a different time with the same arguments, it will produce the same result. In comparison, <i>procedures</i> or <i>subroutines</i> are more complicated - for example, they could also: |
||
− | * it has no ''side effects'', that is to say, invoking it produces no observable effect other than the result it returns; it cannot also ''e.g.'' write to disk, or print to a screen. |
||
+ | * read from or write to [[Global variables|global variables]], |
||
⚫ | |||
+ | * send data to a file, |
||
+ | * or print to a screen. |
||
− | A programming language may be |
+ | A programming language may sometimes be known as <i>purely functional</i> if: |
− | |||
⚫ | |||
+ | * it only permits programs to be defined in terms of pure definitions, |
||
+ | * and functions are its primary means of abstraction. |
||
+ | |||
⚫ | |||
* [http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.27.7800 What is a Purely Functional Language?] a 1993 paper which presents a proposed formal definition of the concept, |
* [http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.27.7800 What is a Purely Functional Language?] a 1993 paper which presents a proposed formal definition of the concept, |
||
* [http://conal.net/blog/posts/the-c-language-is-purely-functional The C language is purely functional] (some satire intended), |
* [http://conal.net/blog/posts/the-c-language-is-purely-functional The C language is purely functional] (some satire intended), |
||
* [http://conal.net/blog/posts/is-haskell-a-purely-functional-language Is Haskell a purely functional language?] |
* [http://conal.net/blog/posts/is-haskell-a-purely-functional-language Is Haskell a purely functional language?] |
||
* [https://stackoverflow.com/questions/4865616/purity-vs-referential-transparency Purity vs Referential transparency], Stack Overflow. |
* [https://stackoverflow.com/questions/4865616/purity-vs-referential-transparency Purity vs Referential transparency], Stack Overflow. |
||
+ | |||
+ | ==== See also ==== |
||
+ | * [https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0078r0.pdf The [[<b><tt>pure</tt></b>]] attribute], JTC1.22.32 Programming Language Evolution Working Group (2015). |
||
[[Category:Glossary]] |
[[Category:Glossary]] |
Latest revision as of 02:00, 17 October 2024
(In contrast to applied, when distinguishing between applied and pure mathematics; the latter being divorced from the real world
.)
In mathematics, functions are pure - they merely associate each possible input value with an output value, and nothing more. In Haskell, most functions uphold this principle. As a result, they usually are referentially transparent - each of them does not depend on anything other than its parameters, so when invoked in a different context or at a different time with the same arguments, it will produce the same result. In comparison, procedures or subroutines are more complicated - for example, they could also:
- read from or write to global variables,
- send data to a file,
- or print to a screen.
A programming language may sometimes be known as purely functional if:
- it only permits programs to be defined in terms of pure definitions,
- and functions are its primary means of abstraction.
However there has been some debate in the past as to the precise meaning of these terms:
- What is a Purely Functional Language? a 1993 paper which presents a proposed formal definition of the concept,
- The C language is purely functional (some satire intended),
- Is Haskell a purely functional language?
- Purity vs Referential transparency, Stack Overflow.
See also
- The [[pure]] attribute, JTC1.22.32 Programming Language Evolution Working Group (2015).