This is my very first seminar presentation. It was presented at an event organized by Adama Science And Technology University Computer Science And Engineering Club. Here I discuss the basic concepts in the world of functional programming.
9. Basic FP Concepts
Functions as a first-class-citizens
Immutable values over mutable variables
Currying, partial application of functions
Laziness, deferred execution
Avoiding side-effects
DRY
Thinking Functional
10. ”
“A first-class citizen : an entity which supports
all the operations generally available to other
entities. These operations typically include
being passed as an argument, returned from
a function, and assigned to a variable.
SCOTT, MICHAEL (2006). PROGRAMMING LANGUAGE PRAGMATICS
Demo
Thinking Functional
11. Side-effects
a function or expression is said to have a side effect if it modifies some
state or has an observable interaction with calling functions or the
outside world.
For example, a particular function might modify a global variable or
static variable, modify one of its arguments, raise an exception, write
data to a display or file, read data, or call other side-effecting functions.
In the presence of side effects, a program's behaviour may depend on
history; that is, the order of evaluation matters. Understanding and
debugging a function with side effects requires knowledge about the
context and its possible histories.
Thinking Functional
12. Pure vs Impure
The function always evaluates the same result value given the same argument
value(s). The function result value cannot depend on any hidden information or
state that may change while program execution proceeds or between different
executions of the program, nor can it depend on any external input from I/O
devices.
Evaluation of the result does not cause any semantically observable side effect or
output, such as mutation of mutable objects or output to I/O devices.
Pure: sin(x)
Impure: random()
15. Declarative programming
Declarative programming: A style of building the structure and
elements of computer programs — that expresses the logic of a
computation without describing its control flow.
E.g: Database query languages (e.g., SQL), regular expressions,
logic programming (e.g., Prolog), functional programming.