Site banner
.
Home Forums Blogs Articles Photos Videos Contact FAQ                    
.
.
Wisdom Archive
Body Mind and Soul
Faith and Belief
God and Religion
Law of Attraction
Life and Beyond
Love and Happiness
Peace of Mind
Peace on Earth
Personal Faith
Spiritual Festivals
Spiritual Growth
Spiritual Guidance
Spiritual Inspiration
Spirituality and Science
Spiritual Retreats
More Wisdom
Buddhism Archives
Hinduism Archives
Sustainability
Theology Archives
Even more Wisdom
2012 - Year 2012
Affirmations
Aura
Ayurveda
Chakras
Consciousness
Cultural Creatives
Diksha (Deeksha)
Dream Dictionary
Dream Interpretation
Dream interpreter
Dreams
Enlightenment
Essential Oils
Feng Shui
Flower Essences
Gaia Hypothesis
Indigo Children
Kalki Bhagavan
Karma
Kundalini
Kundalini Yoga
Life after death
Mayan Calendar
Meaning of Dreams
Meditation
Morphogenetic Fields
Psychic Ability
Reincarnation
Spiritual Art, Music & Dance
Spiritual Awakening
Spiritual Enlightenment
Spiritual Healing
Spirituality and Health
Spiritual Jokes
Spiritual Parenting
Vastu Shastra
Womens Spirituality
Yoga Positions
Site map 2
Site map


Dream Sharing Forum

at Global Oneness Community.

Share your dreams and let others help you with the interpretation!
Dream Sharing Forum



.

Functional programming - Pure functions

Functional programming - Pure functions: Encyclopedia II - Functional programming - Pure functions

Purely functional programs have no side-effects. Since functions do not modify state, no data may be changed by parallel function calls. For this reason, pure functions are always thread-safe, a fact which is exploited by languages that use call-by-future evaluation. Because ordering of side-effects does not have to be preserved in their absence, some languages (such as Haskell) use call-by-need evaluation for pure functions. "Pure" functional programming languages typically enforce referential transparency, which is the notion ...

See also:

Functional programming, Functional programming - History, Functional programming - Higher-order functions, Functional programming - Comparison with imperative programming, Functional programming - Pure functions, Functional programming - Monads, Functional programming - Expansion of functional programming, Functional programming - Speed and space considerations, Functional programming - Functional languages

Functional programming, Functional programming - Comparison with imperative programming, Functional programming - Expansion of functional programming, Functional programming - Functional languages, Functional programming - Higher-order functions, Functional programming - History, Functional programming - Monads, Functional programming - Pure functions, Functional programming - Speed and space considerations, Eager evaluation, Lazy evaluation, Purely functional, List of functional programming topics, Function-level programming (compare and contrast), Procedural programming (contrast), Imperative programming (contrast), Programming paradigm, Nested function

Functional programming: Encyclopedia II - Functional programming - Pure functions



Functional programming - Pure functions

Purely functional programs have no side-effects. Since functions do not modify state, no data may be changed by parallel function calls. For this reason, pure functions are always thread-safe, a fact which is exploited by languages that use call-by-future evaluation. Because ordering of side-effects does not have to be preserved in their absence, some languages (such as Haskell) use call-by-need evaluation for pure functions.

"Pure" functional programming languages typically enforce referential transparency, which is the notion that 'equals can be substituted for equals': if two expressions have "equal" values (for some notion of equality), then one can be substituted for the other in any larger expression without affecting the result of the computation. For example, in

    y = f(x) * f(x);

a compiler can factor out f(x) if it is pure, transforming the program to

    z = f(x);
    y = z * z;

and eliminating the second evaluation of the (possibly costly) call to f(x).

This optimization is called common subexpression elimination.

However, if a function has effects, the function call cannot be eliminated. Consider the following program fragment:

    y = random() * random();

The second call to random cannot be eliminated, because its return value may be different from that of the first call (the random function is not idempotent).

Similarly,

    y = printf("x") * printf("x");

cannot be optimized away; even if printf returns the same value both times, failing to make the second call would result in different program output.

Many modern compilers for imperative programming languages do not perform common subexpression elimination for function calls, because they do not track whether a function is pure. It is possible for an advanced compiler to infer whether a local function has effects and optimize accordingly; however, most pre-compiled libraries do not expose this information, preventing calls to external functions from being optimized away. Some compilers, such as gcc, add extra keywords for a programmer to explicitly mark pure functions so that this optimization can be performed.

Functional programming - Monads

Some functional languages remove or sandbox side-effects during evaluation using monads. In such languages, all functions become "pure"; the program's evaluation can then be reasoned about using traditional mathematical techniques, and common-subexpression elimination can be performed on all function calls. Because monadic functions depend on the monad values produced by previous function calls, multiple calls still cannot be eliminated; however, their sequencing is made explicit in the program.

Alternative methods (such as Hoare logic) have been developed to track effects in programs. Some modern research languages use effect systems to make explicit the presence of effects.

Other related archives

1930s, 1950s, 1970s, 1980s, Alonzo Church, C, COBOL, CPU, Category:Functional languages, Clean, Common Lisp, David Turner, Dylan, Eager evaluation, Erlang, FORTRAN 77, Function-level programming, Haskell, Haskell programming language, Hindley-Milner, Hoare logic, IBM 700/7000 series, Imperative programming, Information Processing Language, Information Processing Language (IPL), Iteration, J, JOHNNIAC, John McCarthy, K, LISP, Lambda calculus, Lazy evaluation, Lisp, List of functional programming topics, Logo, MIT, ML, ML programming language, Maple, Mathematica, Miranda, Nested function, OCaml, Objective Caml, Pascal, Perl, Procedural programming, Programming paradigm, Purely functional, Python, RAND Corporation, Recursive functions, Robin Milner, Ruby, SML, Scheme, Scheme programming language, Standard ML, Tcl, University of Edinburgh, University of Kent, Xslt, academics, array, bounds checking, calculus, call-by-future evaluation, call-by-need evaluation, citation needed, closures, common subexpression elimination, compiler, computation, continuations, correctness, currying, differential operator, effect systems, first-class functions, functions, garbage collection, gcc, higher-order functions, idempotent, imperative programming, mathematical functions, monads, persistent data structures, procedural programming, program, programming paradigm, quantum algorithms, recursion, referential transparency, sandbox, several dialects, side-effects, software industry, state machines, tail recursion, thread-safe



Adapted from the Wikipedia article "Pure functions", under the G.N U Free Docmentation License. Please also see http://en.wikipedia.org/wiki

More material related to Functional Programming can be found here:
Main Page
for
Functional Programming
Index of Articles
related to
Functional Programming


« Back








Search the Global Oneness web site
Global Oneness is a huge, really huge, web site. Almost whatever you are searching for within health, spirituality, personal development and inspirationals - you will find it here!
Google
 
 

Rate this article!

Please rate this article with 10 as very good and 1 as very poor.

.








Sneak-Peek of Global Oneness Community

Hi friend! The Global Oneness Community, the place for information and sharing about Oneness is not really launched yet (you will see there is still some clean up to do) ...but it is now open for a sneak-peek! And if you wish - please register and become one of the very first members to do so! Jonas

Forum Home, Articles, Photo Gallery, Videos, News, Sitemap
...and much more!


Dream Sharing Forum

at Global Oneness Community.

Share your dreams and let others help you with the interpretation!
Dream Sharing Forum



Forum
Articles
Images Pictures
Videos
News
Sitemap




 

 

 

 

 


 








  » Home » » Home »