BY:
SHUBHANGI SHARMA
ASSISTANT PROFESSOR
DEPARTMENT OF CSE
,Functional Programming
Functional programming is a programming
paradigm in which we try to bind everything in
pure mathematical functions style.
It is a declarative type of programming style.
Its main focus is on “what to solve” in
contrast to an imperative style where the
main focus is “how to solve“.
It uses expressions instead of statements. An
expression is evaluated to produce a value
whereas a statement is executed to assign
variables
,Pure Functions
Pure functions have two properties.
It always produces the same output for the same arguments.
For example, 3+7 will always be 10 no matter what.
It does not change or modifies the input variable.
The second property is also known as immutability. The only
result of the Pure Function is the value it returns. They are
deterministic. Programs done using functional programming
are easy to debug because pure functions have no side
effects or hidden I/O. Pure functions also make it easier to
write parallel/concurrent applications. When the code is
written in this style, a smart compiler can do many things – it
can parallelize the instructions, wait to evaluate results when
needing them, and memorize the results since the results
never change as long as the input doesn’t change.
, First-Class Functions/Higher-Order
Functions
First-class objects are handled uniformly throughout.
They may be stored in data structures, passed as
arguments, or used in control structures. A
programming language is said to support first-class
functions if it treats functions as first-class objects.
Properties of first class functions:
A function is an instance of the Object type.
You can store the function in a variable.
You can pass the function as a parameter to another
function.
You can return the function from a function.
You can store them in data structures such as hash
tables, lists, …