Pure

From HaskellWiki
Revision as of 04:16, 12 April 2024 by Atravers (talk | contribs) (More emphasis placed on the mathematical concept of a function)
Jump to navigation Jump to search

(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. This is in contrast to procedures or subroutines that, for example, 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: