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:

    Gross and obscure natures, however decorated, seem impure shambles; but character gives splendor to youth, and awe to wrinkled skin and gray hairs.
    Ralph Waldo Emerson (1803–1882)

    Let us stop being afraid. Of our own thoughts, our own minds. Of madness, our own or others’. Stop being afraid of the mind itself, its astonishing functions and fandangos, its complications and simplifications, the wonderful operation of its machinery—more wonderful because it is not machinery at all or predictable.
    Kate Millett (b. 1934)

    Like most vigorous-minded men, seeing that there was no stopping-place between dogma and negation, he preferred to accept dogma. Of all weaknesses he most disliked timed and half-hearted faith. He would rather have jumped at once to Strong’s pure denial, than yield an inch to the argument that a mystery was to be paltered with because it could not be explained.
    Henry Brooks Adams (1838–1918)

    Many expressions in the New Testament come naturally to the lips of all Protestants, and it furnishes the most pregnant and practical texts. There is no harmless dreaming, no wise speculation in it, but everywhere a substratum of good sense. It never reflects, but it repents. There is no poetry in it, we may say, nothing regarded in the light of beauty merely, but moral truth is its object. All mortals are convicted by its conscience.
    Henry David Thoreau (1817–1862)