Difference between revisions of "Pure"

From HaskellWiki
Jump to navigation Jump to search
m
m
 
Line 19: Line 19:
   
 
==== See also ====
 
==== See also ====
* The <tt><nowiki>[[pure]]</nowiki></tt> attribute[https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0078r0.pdf <span></span>], JTC1.22.32 Programming Language Evolution Working Group (2015).
+
* [https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0078r0.pdf The &#91;&#91;<b><tt>pure</tt></b>&#93;&#93; 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:

See also