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)

    Mark the babe
    Not long accustomed to this breathing world;
    One that hath barely learned to shape a smile,
    Though yet irrational of soul, to grasp
    With tiny finger—to let fall a tear;
    And, as the heavy cloud of sleep dissolves,
    To stretch his limbs, bemocking, as might seem,
    The outward functions of intelligent man.
    William Wordsworth (1770–1850)

    Human life itself may be almost pure chaos, but the work of the artist—the only thing he’s good for—is to take these handfuls of confusion and disparate things, things that seem to be irreconcilable, and put them together in a frame to give them some kind of shape and meaning. Even if it’s only his view of a meaning. That’s what he’s for—to give his view of life.
    Katherine Anne Porter (1890–1980)

    Whatever offices of life are performed by women of culture and refinement are thenceforth elevated; they cease to be mere servile toils, and become expressions of the ideas of superior beings.
    Harriet Beecher Stowe (1811–1896)