SlideShare ist ein Scribd-Unternehmen logo
1 von 19
Downloaden Sie, um offline zu lesen
FUNCTIONAL
PROGRAMMING
Hideshi Ogoshi
YNS Philippines Inc.
Aug-11-2016
WHAT IS PARADIGM SHIFT
➤ Paradigm shift is a fundamental change in the basic concepts
and experimental practices of a scientific discipline.
Before Copernicus: The Sun goes around the Earth
After Copernicus: The Earth goes around the Sun
PARADIGM SHIFT IN PROGRAMMING LANGUAGE
From what to what?
From: Procedural programming
To: Functional programming
PROGRAMMING LANGUAGES MAP
C
Pascal
Fortran
BASIC
C++
Python
PHP
Java
C#
Ruby
JavaScript
Procedural
Object Oriented Functional
Scala
LISP
Haskell
OCaml
Clojure
Erlang
Elixir
DIFFERENCE BETWEEN PROCEDURAL AND FUNCTIONAL
➤Procedural programming language describes how to do.
array = [1, 2, 3, 4, 5];
result = [];
for(i = 0; i < length(array); i++) {
if(array[i] % 2 == 0) {
result.append(array[i] * 2);
}
}
➤Functional programming language describes what to do.
result = range(1 to 5)
.filter(fn(x){x % 2 == 0})
.map(fn(x){x * 2});
WHAT IS FUNCTION IN MATHEMATICS
➤ A function is a relation between a set of inputs and a set of
permissible outputs with the property that each input is
related to exactly one output.
f(x) = x + 2
f(1) = 1 + 2 = 3
f(3) = 3 + 2 = 5
f(3) = 3 + 2 = 3
WHAT IS FUNCTION IN PROCEDURAL PROGRAMMING LANGUAGE
➤ In the procedural programming
language, original meaning of
the function is exactly the same
as the definition of mathematics.
So it can return value.
fn plus_two(x) {
return x + 2;
}
res1 = plus_two(1);
print(res1);
==> 3
res2 = plus_two(3);
print(res1);
==> 5
➤ It can be used to process
something without returning value.
fn do_something(object) {
object.foo = ‘baz’;
}
obj = new SomeObject();
obj.foo = ‘bar’;
res = do_something(obj);
print(gettype(res));
==> NULL
print(obj);
==> {‘foo’ => ‘baz’}
WHAT IS FUNCTION IN FUNCTIONAL PROGRAMMING LANGUAGE
➤ In the functional
programming language,
meaning of the function is
exactly and strictly the same
as the definition of
mathematics. So it is always
expected to return value.
fn plus_two(x) {
x + 2;
}
res1 = plus_two(1);
print(res1);
==> 3
res2 = plus_two(3);
print(res1);
==> 5
TERMS OF FUNCTIONAL PROGRAMMING LANGUAGE
➤ First-class function
➤ Mutability and Immutability
➤ Referential transparency and Side effect
➤ Recursion
➤ Closure
➤ Lazy evaluation and Eager evaluation
FIRST-CLASS FUNCTION
➤ Functions are treated as first-class citizens in the language
➤ The language supports passing functions as arguments to
other functions, returning them as the values from other
functions, and assigning them to variables or storing them in
data structures.
➤ This kind of function is called higher-order function.
MUTABILITY AND IMMUTABILITY
➤ Mutability: Characteristic of able to be changed
foo = ‘bar’;
foo = ‘baz’;
➤ Immutability: Characteristic of unable to be changed
foo = ‘bar’;
foo = ‘baz’;
❌
REFERENTIAL TRANSPARENCY AND SIDE EFFECT
➤ Referential transparency is that a
function or an expression is said
to be referentially transparent if
it can be replaced with other
value without changing the
behavior of a program.
fn sum(array) {
result = 0;
i = 0;
len = length(array);
while(len > i) {
result += array[i];
i++;
}
return result;
}
fn sum(array) {
result = 0;
for(i = 0; i < length(array); i++) {
result += array[i];
}
return result;
}
➤ Side effect is that 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.
fn do_many_thing_with_side_effect(obj) {
f = open(‘foo.txt’, ‘r’);
line = [];
while(line = f.readline()) {
lines.append(line);
print(line);
}
obj.data = lines;
}
RECURSION
➤ Recursion is one of the ways for functions to process a collection
data, such as list, by calling itself inside of itself.
➤ The function process the first element of the list and passing rest of
the list to itself. If the function consumed all the elements in the list,
the function just return accumulator as a result.
fn map(list, func, accumulator) {
if(length(list) == 0) {
return accumulator;
} else {
head, tail = list.split();
accumulator.append(func.call(head));
map(tail, func, accumulator);
}
}
res = map([1, 2, 3], plus2, []);
print(res);
==> [3, 4, 5];
map([1, 2, 3], plus2, []);
map([2, 3], plus2, [3]);
map([3], plus2, [3, 4]);
map([], plus2, [3, 4, 5]);
CLOSURE
➤ Closure is a kind of functions, which accepts variables or functions as arguments and makes
its behaviour dynamic in accordance with its arguments.
➤ Closure is supposed to return function.
fn make_plus(num) {
func = fn (x) {
return x + num;
}
return func;
}
plus1 = make_plus(1);
print(gettype(plus1));
==> function
print(plus1.call(2));
==> 3
plus3 = make_plus(3);
print(plus3.call(4));
==> 7
LAZY EVALUATION AND EAGER EVALUATION
➤ Lazy evaluation is one of the strategies to process the data by
postponing the evaluation of its arguments.
result = range(1 to 1_000_000_000)
.lazy_map(very_expensive_function)
.lazy_filter(fn(x) {
if(x % 2 == 0) {
return true;
} else {
return false;
})
.take(10);
MODULARITY OF FUNCTIONAL PROGRAMMING
➤ Modularity is one of the important ways to compose software for the maintainability, testability and
quality.
➤ It ensure each function to have its own responsibility and make those functions loosely coupling each other
Function without side effect
Function without side effect
Function without side effect
Function without side effect
Function with few side effects
Function with many side effects
BENEFIT OF FUNCTIONAL PROGRAMMING
➤ Realizes higher modularity, testability and quality by adopting
test driven development with peace of mind.
➤ Test driven development enable us to enhance continuous
integration.
➤ Make us easily understand languages or frameworks, which
are based on functional programming paradigm, such as
reactive functional programming.
FUNCTIONAL PROGRAMMING LANGUAGES
THANK YOU

Weitere ähnliche Inhalte

Was ist angesagt? (20)

Recursion
RecursionRecursion
Recursion
 
A brief introduction to lisp language
A brief introduction to lisp languageA brief introduction to lisp language
A brief introduction to lisp language
 
INTRODUCTION TO LISP
INTRODUCTION TO LISPINTRODUCTION TO LISP
INTRODUCTION TO LISP
 
LISP: Introduction to lisp
LISP: Introduction to lispLISP: Introduction to lisp
LISP: Introduction to lisp
 
Function overloading(C++)
Function overloading(C++)Function overloading(C++)
Function overloading(C++)
 
Optimization of dfa
Optimization of dfaOptimization of dfa
Optimization of dfa
 
C# p5
C# p5C# p5
C# p5
 
C# p8
C# p8C# p8
C# p8
 
(Ai lisp)
(Ai lisp)(Ai lisp)
(Ai lisp)
 
AI Lesson 13
AI Lesson 13AI Lesson 13
AI Lesson 13
 
Hima1
Hima1Hima1
Hima1
 
Recursion
RecursionRecursion
Recursion
 
Introduction to Programming in LISP
Introduction to Programming in LISPIntroduction to Programming in LISP
Introduction to Programming in LISP
 
The Expression Problem - Part 1
The Expression Problem - Part 1The Expression Problem - Part 1
The Expression Problem - Part 1
 
Cis068 08
Cis068 08Cis068 08
Cis068 08
 
Lisp
LispLisp
Lisp
 
AI Lesson 16
AI Lesson 16AI Lesson 16
AI Lesson 16
 
Ch3
Ch3Ch3
Ch3
 
The Expression Problem - Part 2
The Expression Problem - Part 2The Expression Problem - Part 2
The Expression Problem - Part 2
 
Introduction To Lisp
Introduction To LispIntroduction To Lisp
Introduction To Lisp
 

Andere mochten auch

How to create test data
How to create test dataHow to create test data
How to create test dataHideshi Ogoshi
 
System performance tuning
System performance tuningSystem performance tuning
System performance tuningMenandro Oba
 
Learning CakePHP2 from source code vol2
Learning CakePHP2 from source code vol2Learning CakePHP2 from source code vol2
Learning CakePHP2 from source code vol2Hideshi Ogoshi
 
Cake PHP 3 Presentaion
Cake PHP 3 PresentaionCake PHP 3 Presentaion
Cake PHP 3 Presentaionglslarmenta
 
Falcon Full Text Search Engine
Falcon Full Text Search EngineFalcon Full Text Search Engine
Falcon Full Text Search EngineHideshi Ogoshi
 
Learning CakePHP from Source Code
Learning CakePHP from Source CodeLearning CakePHP from Source Code
Learning CakePHP from Source CodeHideshi Ogoshi
 
The essence of Reactive Programming
The essence of Reactive ProgrammingThe essence of Reactive Programming
The essence of Reactive ProgrammingEddy Bertoluzzo
 
1.7 functional programming
1.7 functional programming1.7 functional programming
1.7 functional programmingfuturespective
 
Elm & Elixir: Functional Programming and Web
Elm & Elixir: Functional Programming and WebElm & Elixir: Functional Programming and Web
Elm & Elixir: Functional Programming and WebPublitory
 
Designing with Capabilities
Designing with CapabilitiesDesigning with Capabilities
Designing with CapabilitiesScott Wlaschin
 
Real-World Functional Programming @ Incubaid
Real-World Functional Programming @ IncubaidReal-World Functional Programming @ Incubaid
Real-World Functional Programming @ IncubaidNicolas Trangez
 
MySQL対応全文検索システムMroonga(むるんが)
MySQL対応全文検索システムMroonga(むるんが)MySQL対応全文検索システムMroonga(むるんが)
MySQL対応全文検索システムMroonga(むるんが)Hideshi Ogoshi
 
Slick 3.0 functional programming and db side effects
Slick 3.0   functional programming and db side effectsSlick 3.0   functional programming and db side effects
Slick 3.0 functional programming and db side effectsJoost de Vries
 

Andere mochten auch (20)

How to create test data
How to create test dataHow to create test data
How to create test data
 
Software Testing
Software Testing Software Testing
Software Testing
 
System performance tuning
System performance tuningSystem performance tuning
System performance tuning
 
Learning CakePHP2 from source code vol2
Learning CakePHP2 from source code vol2Learning CakePHP2 from source code vol2
Learning CakePHP2 from source code vol2
 
Node js - Yns
Node js - YnsNode js - Yns
Node js - Yns
 
Php 7 - YNS
Php 7 - YNSPhp 7 - YNS
Php 7 - YNS
 
Cake PHP 3 Presentaion
Cake PHP 3 PresentaionCake PHP 3 Presentaion
Cake PHP 3 Presentaion
 
Falcon Full Text Search Engine
Falcon Full Text Search EngineFalcon Full Text Search Engine
Falcon Full Text Search Engine
 
Learning CakePHP from Source Code
Learning CakePHP from Source CodeLearning CakePHP from Source Code
Learning CakePHP from Source Code
 
The essence of Reactive Programming
The essence of Reactive ProgrammingThe essence of Reactive Programming
The essence of Reactive Programming
 
Frp
FrpFrp
Frp
 
1.7 functional programming
1.7 functional programming1.7 functional programming
1.7 functional programming
 
Elm & Elixir: Functional Programming and Web
Elm & Elixir: Functional Programming and WebElm & Elixir: Functional Programming and Web
Elm & Elixir: Functional Programming and Web
 
The taste of F#
The taste of F#The taste of F#
The taste of F#
 
Designing with Capabilities
Designing with CapabilitiesDesigning with Capabilities
Designing with Capabilities
 
Doge-driven design
Doge-driven designDoge-driven design
Doge-driven design
 
Real-World Functional Programming @ Incubaid
Real-World Functional Programming @ IncubaidReal-World Functional Programming @ Incubaid
Real-World Functional Programming @ Incubaid
 
The Theory of Chains
The Theory of ChainsThe Theory of Chains
The Theory of Chains
 
MySQL対応全文検索システムMroonga(むるんが)
MySQL対応全文検索システムMroonga(むるんが)MySQL対応全文検索システムMroonga(むるんが)
MySQL対応全文検索システムMroonga(むるんが)
 
Slick 3.0 functional programming and db side effects
Slick 3.0   functional programming and db side effectsSlick 3.0   functional programming and db side effects
Slick 3.0 functional programming and db side effects
 

Ähnlich wie Functional programming

Introduction to R
Introduction to RIntroduction to R
Introduction to Ragnonchik
 
Intro f# functional_programming
Intro f# functional_programmingIntro f# functional_programming
Intro f# functional_programmingMauro Ghiani
 
TI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class FunctionsTI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class FunctionsEelco Visser
 
Functional programming in clojure
Functional programming in clojureFunctional programming in clojure
Functional programming in clojureJuan-Manuel Gimeno
 
Functional Programming for OO Programmers (part 2)
Functional Programming for OO Programmers (part 2)Functional Programming for OO Programmers (part 2)
Functional Programming for OO Programmers (part 2)Calvin Cheng
 
Functional Programming in F#
Functional Programming in F#Functional Programming in F#
Functional Programming in F#Dmitri Nesteruk
 
Functional Programming by Examples using Haskell
Functional Programming by Examples using HaskellFunctional Programming by Examples using Haskell
Functional Programming by Examples using Haskellgoncharenko
 
Why you should care about functional programming
Why you should care about functional programmingWhy you should care about functional programming
Why you should care about functional programmingDhananjay Nene
 
To Infinity & Beyond: Protocols & sequences in Node - Part 1
To Infinity & Beyond: Protocols & sequences in Node - Part 1To Infinity & Beyond: Protocols & sequences in Node - Part 1
To Infinity & Beyond: Protocols & sequences in Node - Part 1Bahul Neel Upadhyaya
 
Programming in Computational Biology
Programming in Computational BiologyProgramming in Computational Biology
Programming in Computational BiologyAtreyiB
 
Thinking Functionally with JavaScript
Thinking Functionally with JavaScriptThinking Functionally with JavaScript
Thinking Functionally with JavaScriptLuis Atencio
 
Dev Concepts: Functional Programming
Dev Concepts: Functional ProgrammingDev Concepts: Functional Programming
Dev Concepts: Functional ProgrammingSvetlin Nakov
 
Composition birds-and-recursion
Composition birds-and-recursionComposition birds-and-recursion
Composition birds-and-recursionDavid Atchley
 
Functional programming in javascript
Functional programming in javascriptFunctional programming in javascript
Functional programming in javascriptBoris Burdiliak
 
Elements of Functional Programming in PHP
Elements of Functional Programming in PHPElements of Functional Programming in PHP
Elements of Functional Programming in PHPJarek Jakubowski
 
Столпы функционального программирования для адептов ООП, Николай Мозговой
Столпы функционального программирования для адептов ООП, Николай МозговойСтолпы функционального программирования для адептов ООП, Николай Мозговой
Столпы функционального программирования для адептов ООП, Николай МозговойSigma Software
 
Immutability and pure functions
Immutability and pure functionsImmutability and pure functions
Immutability and pure functionssparkfabrik
 

Ähnlich wie Functional programming (20)

Functional programming
Functional programmingFunctional programming
Functional programming
 
Introduction to R
Introduction to RIntroduction to R
Introduction to R
 
Intro f# functional_programming
Intro f# functional_programmingIntro f# functional_programming
Intro f# functional_programming
 
TI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class FunctionsTI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class Functions
 
Functional programming in clojure
Functional programming in clojureFunctional programming in clojure
Functional programming in clojure
 
Functional Programming for OO Programmers (part 2)
Functional Programming for OO Programmers (part 2)Functional Programming for OO Programmers (part 2)
Functional Programming for OO Programmers (part 2)
 
Functional Programming in F#
Functional Programming in F#Functional Programming in F#
Functional Programming in F#
 
Scala functions
Scala functionsScala functions
Scala functions
 
Functional Programming by Examples using Haskell
Functional Programming by Examples using HaskellFunctional Programming by Examples using Haskell
Functional Programming by Examples using Haskell
 
Why you should care about functional programming
Why you should care about functional programmingWhy you should care about functional programming
Why you should care about functional programming
 
To Infinity & Beyond: Protocols & sequences in Node - Part 1
To Infinity & Beyond: Protocols & sequences in Node - Part 1To Infinity & Beyond: Protocols & sequences in Node - Part 1
To Infinity & Beyond: Protocols & sequences in Node - Part 1
 
Programming in Computational Biology
Programming in Computational BiologyProgramming in Computational Biology
Programming in Computational Biology
 
Special topics in finance lecture 2
Special topics in finance   lecture 2Special topics in finance   lecture 2
Special topics in finance lecture 2
 
Thinking Functionally with JavaScript
Thinking Functionally with JavaScriptThinking Functionally with JavaScript
Thinking Functionally with JavaScript
 
Dev Concepts: Functional Programming
Dev Concepts: Functional ProgrammingDev Concepts: Functional Programming
Dev Concepts: Functional Programming
 
Composition birds-and-recursion
Composition birds-and-recursionComposition birds-and-recursion
Composition birds-and-recursion
 
Functional programming in javascript
Functional programming in javascriptFunctional programming in javascript
Functional programming in javascript
 
Elements of Functional Programming in PHP
Elements of Functional Programming in PHPElements of Functional Programming in PHP
Elements of Functional Programming in PHP
 
Столпы функционального программирования для адептов ООП, Николай Мозговой
Столпы функционального программирования для адептов ООП, Николай МозговойСтолпы функционального программирования для адептов ООП, Николай Мозговой
Столпы функционального программирования для адептов ООП, Николай Мозговой
 
Immutability and pure functions
Immutability and pure functionsImmutability and pure functions
Immutability and pure functions
 

Kürzlich hochgeladen

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 

Kürzlich hochgeladen (20)

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 

Functional programming

  • 2. WHAT IS PARADIGM SHIFT ➤ Paradigm shift is a fundamental change in the basic concepts and experimental practices of a scientific discipline. Before Copernicus: The Sun goes around the Earth After Copernicus: The Earth goes around the Sun
  • 3. PARADIGM SHIFT IN PROGRAMMING LANGUAGE From what to what? From: Procedural programming To: Functional programming
  • 5. DIFFERENCE BETWEEN PROCEDURAL AND FUNCTIONAL ➤Procedural programming language describes how to do. array = [1, 2, 3, 4, 5]; result = []; for(i = 0; i < length(array); i++) { if(array[i] % 2 == 0) { result.append(array[i] * 2); } } ➤Functional programming language describes what to do. result = range(1 to 5) .filter(fn(x){x % 2 == 0}) .map(fn(x){x * 2});
  • 6. WHAT IS FUNCTION IN MATHEMATICS ➤ A function is a relation between a set of inputs and a set of permissible outputs with the property that each input is related to exactly one output. f(x) = x + 2 f(1) = 1 + 2 = 3 f(3) = 3 + 2 = 5 f(3) = 3 + 2 = 3
  • 7. WHAT IS FUNCTION IN PROCEDURAL PROGRAMMING LANGUAGE ➤ In the procedural programming language, original meaning of the function is exactly the same as the definition of mathematics. So it can return value. fn plus_two(x) { return x + 2; } res1 = plus_two(1); print(res1); ==> 3 res2 = plus_two(3); print(res1); ==> 5 ➤ It can be used to process something without returning value. fn do_something(object) { object.foo = ‘baz’; } obj = new SomeObject(); obj.foo = ‘bar’; res = do_something(obj); print(gettype(res)); ==> NULL print(obj); ==> {‘foo’ => ‘baz’}
  • 8. WHAT IS FUNCTION IN FUNCTIONAL PROGRAMMING LANGUAGE ➤ In the functional programming language, meaning of the function is exactly and strictly the same as the definition of mathematics. So it is always expected to return value. fn plus_two(x) { x + 2; } res1 = plus_two(1); print(res1); ==> 3 res2 = plus_two(3); print(res1); ==> 5
  • 9. TERMS OF FUNCTIONAL PROGRAMMING LANGUAGE ➤ First-class function ➤ Mutability and Immutability ➤ Referential transparency and Side effect ➤ Recursion ➤ Closure ➤ Lazy evaluation and Eager evaluation
  • 10. FIRST-CLASS FUNCTION ➤ Functions are treated as first-class citizens in the language ➤ The language supports passing functions as arguments to other functions, returning them as the values from other functions, and assigning them to variables or storing them in data structures. ➤ This kind of function is called higher-order function.
  • 11. MUTABILITY AND IMMUTABILITY ➤ Mutability: Characteristic of able to be changed foo = ‘bar’; foo = ‘baz’; ➤ Immutability: Characteristic of unable to be changed foo = ‘bar’; foo = ‘baz’; ❌
  • 12. REFERENTIAL TRANSPARENCY AND SIDE EFFECT ➤ Referential transparency is that a function or an expression is said to be referentially transparent if it can be replaced with other value without changing the behavior of a program. fn sum(array) { result = 0; i = 0; len = length(array); while(len > i) { result += array[i]; i++; } return result; } fn sum(array) { result = 0; for(i = 0; i < length(array); i++) { result += array[i]; } return result; } ➤ Side effect is that 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. fn do_many_thing_with_side_effect(obj) { f = open(‘foo.txt’, ‘r’); line = []; while(line = f.readline()) { lines.append(line); print(line); } obj.data = lines; }
  • 13. RECURSION ➤ Recursion is one of the ways for functions to process a collection data, such as list, by calling itself inside of itself. ➤ The function process the first element of the list and passing rest of the list to itself. If the function consumed all the elements in the list, the function just return accumulator as a result. fn map(list, func, accumulator) { if(length(list) == 0) { return accumulator; } else { head, tail = list.split(); accumulator.append(func.call(head)); map(tail, func, accumulator); } } res = map([1, 2, 3], plus2, []); print(res); ==> [3, 4, 5]; map([1, 2, 3], plus2, []); map([2, 3], plus2, [3]); map([3], plus2, [3, 4]); map([], plus2, [3, 4, 5]);
  • 14. CLOSURE ➤ Closure is a kind of functions, which accepts variables or functions as arguments and makes its behaviour dynamic in accordance with its arguments. ➤ Closure is supposed to return function. fn make_plus(num) { func = fn (x) { return x + num; } return func; } plus1 = make_plus(1); print(gettype(plus1)); ==> function print(plus1.call(2)); ==> 3 plus3 = make_plus(3); print(plus3.call(4)); ==> 7
  • 15. LAZY EVALUATION AND EAGER EVALUATION ➤ Lazy evaluation is one of the strategies to process the data by postponing the evaluation of its arguments. result = range(1 to 1_000_000_000) .lazy_map(very_expensive_function) .lazy_filter(fn(x) { if(x % 2 == 0) { return true; } else { return false; }) .take(10);
  • 16. MODULARITY OF FUNCTIONAL PROGRAMMING ➤ Modularity is one of the important ways to compose software for the maintainability, testability and quality. ➤ It ensure each function to have its own responsibility and make those functions loosely coupling each other Function without side effect Function without side effect Function without side effect Function without side effect Function with few side effects Function with many side effects
  • 17. BENEFIT OF FUNCTIONAL PROGRAMMING ➤ Realizes higher modularity, testability and quality by adopting test driven development with peace of mind. ➤ Test driven development enable us to enhance continuous integration. ➤ Make us easily understand languages or frameworks, which are based on functional programming paradigm, such as reactive functional programming.