FP is a programming model that treates computation as the evaluation of mathematical function.
For e.g, if we define two functions like given below
f(x) = x^2 + x + 1
g(x,y) = x * y
A problem f (g (2, 2) ) will be evaluated by compiler as
g(2*2)^2 + g(2*2) + 1
(4)^2 + (4) + 1
16+ 4 + 1
21
It is a declarative way of programming, where we leave the compiler to do the evaluation as late as possible. The user is only bothered about the result and not on how it is being evaluated.The focus is never on in the state transition of the variables, so one need not bother about the side effects.
Advantages:
This gives the compiler as edge to reorder or combine the evaluation of expressions in a program.
I believe it is a very strong feature for a programming language to possess.
0 comments:
Post a Comment