javascript - Order of execution of functions in functional programming -


since past 6 months, started learn concepts of functional programming. while reading many sources, 1 of things found in functional programming, order of execution undefined! don't understand this.

from other stack overflow answer: https://stackoverflow.com/a/23290/1276021, "a functional language" (ideally) allows write "mathematical function".

but, in mathematical functions, f(g(x)) !== g(f(x)) - meaning, order of execution matter.

it seems wrong in understanding concept "order of execution undefined". wrong?

f(g(x)) !== g(f(x)) - meaning, order of execution matter.

no, different expressions/programs, not different order of execution.

it seems wrong in understanding concept "order of execution undefined"

the correct, more verbose statement "the order of evaluation of parts of expression irrelevant" (and lead same result). means such functional language has no side effects , referential transparency - 2 important properties proofs "mathematical" functions have well.

if define 2 functions

f(x) = x*3 g(y) = y+1 

and try evaluate expression f(g(1)), doesn't matter whether first do

  f(g(1)) = f(1+1) = f(2) = 2*3 = 6 

or

  f(g(1)) = g(1)*3 = (1+1)*3 = 2*3 = 6 

we arrive @ 6, regardless of of functions apply first.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -