Pure Function - Impure Functions in Pure Expressions

Impure Functions in Pure Expressions

The definitions above still allow some laxity with regard to purity. It is possible for a pure expression to yield an impure function (or more generally a value which contains one or more impure functions).

It is also possible for an expression to be pure even if one or more of the argument subexpressions yields an impure function (or a value which contains one or more impure functions). In this case the impure function(s) in the argument must not be applied during evaluation (but may be incorporated in the result somehow). However, dealing with programs that allow impure and pure functions to be mixed like this can be quite difficult in practice, thus purely functional programming languages do not allow impure functions to be defined. Effect systems, among other things, allow one to reason precisely and formally about the purity of certain expressions even in the presence of higher-order functions etc.; they even allow to prove that a certain function does not have any side effects although it uses impure operations (for example, uses a mutable array for computation internally, but does not expose it to the outer world or maintain its state between invocations).

Read more about this topic:  Pure Function

Famous quotes containing the words impure, functions, pure and/or expressions:

    “All orthodox opinion—that is, today, “revolutionary” opinion either of the pure or the impure variety—is anti-man.”
    —Wyndham Lewis (1882–1957)

    “Nobody is so constituted as to be able to live everywhere and anywhere; and he who has great duties to perform, which lay claim to all his strength, has, in this respect, a very limited choice. The influence of climate upon the bodily functions ... extends so far, that a blunder in the choice of locality and climate is able not only to alienate a man from his actual duty, but also to withhold it from him altogether, so that he never even comes face to face with it.”
    —Friedrich Nietzsche (1844–1900)

    “It seems to be a rule of wisdom never to rely on your memory alone, scarcely even in acts of pure memory, but to bring the past for judgment into the thousand-eyed present, and live ever in a new day.”
    —Ralph Waldo Emerson (1803–1882)

    “Let it be signified to me through any channel ... that the possession of the Floridas would be desirable to the United States, and in sixty days it will be accomplished.
    ...penned in the language of truth, and divested of those expressions of servility which would persuade his majesty that we are asking favors and not rights.”
    —Thomas Jefferson (1743–1826)