SlideShare a Scribd company logo
ICS 313 - Fundamentals of Programming Languages 1
15. Functional Programming
15.1 Introduction
The design of the imperative languages is based
directly on the von Neumann architecture
Efficiency is the primary concern, rather than the
suitability of the language for software development
The design of the functional languages is based
on mathematical functions
A solid theoretical basis that is also closer to the user, but
relatively unconcerned with the architecture of the
machines on which programs will run
ICS 313 - Fundamentals of Programming Languages 2
15.2 Mathematical Functions
A mathematical function is a mapping of members of one set,
called the domain set, to another set, called the range set
A lambda expression specifies the parameter(s) and the
mapping of a function in the following form
ฮป(x) x * x * x
for the function cube (x) = x * x * x
Lambda expressions describe nameless functions
Lambda expressions are applied to parameter(s) by placing
the parameter(s) after the expression
e.g. (ฮป(x) x * x * x)(3)
which evaluates to 27
15.2 Mathematical Functions (continued)
Functional Forms
A higher-order function, or functional form, is one
that either takes functions as parameters or yields a
function as its result, or both
Function Composition
A functional form that takes two functions as parameters
and yields a function whose result is a function whose
value is the first actual parameter function applied to the
result of the application of the second
Form: h๏€  โ‰ก ๏€ f ยฐ g
which means h (x) โ‰ก ๏€ f ( g ( x))
ICS 313 - Fundamentals of Programming Languages 3
15.2 Mathematical Functions (continued)
Construction
A functional form that takes a list of functions as parameters and yields
a list of the results of applying each of its parameter functions to a
given parameter
Form: [f, g]
For f (x) โ‰ก x * x * x and g (x) โ‰ก x + 3,
[f, g] (4) yields (64, 7)
Apply-to-all
A functional form that takes a single function as a parameter and
yields a list of values obtained by applying the given function to each
element of a list of parameters
Form: ฮฑ
For h (x) โ‰ก ๏€ x * x * x
ฮฑ ๏€ ( h, (3, 2, 4)) yields (27, 8, 64)
15.3 Fundamentals of Functional Programming Languages
The objective of the design of a FPL is to mimic mathematical
functions to the greatest extent possible
The basic process of computation is fundamentally different in
a FPL than in an imperative language
In an imperative language, operations are done and the results
are stored in variables for later use
Management of variables is a constant concern and source of complexity for
imperative programming
In an FPL, variables are not necessary, as is the case in
mathematics
In an FPL, the evaluation of a function always produces the
same result given the same parameters
This is called referential transparency
ICS 313 - Fundamentals of Programming Languages 4
Functional Programming Languages
LISP
Lambda notation is used to specify functions and function definitions, function
applications, and data all have the same form
Scheme
A mid-1970s dialect of LISP, designed to be a cleaner, more modern, and simpler
version than the contemporary dialects of LISP
COMMON LISP
A combination of many of the features of the popular dialects of LISP around in the
early 1980s
ML
A static-scoped functional language with syntax that is closer to Pascal than to LISP
Haskell
Similar to ML (syntax, static scoped, strongly typed, type inferencing)
Different from ML (and most other functional languages) in that it is PURELY
functional (e.g., no variables, no assignment statements, and no side effects of any
kind)
15.8 Haskell
Most Important Features
Uses lazy evaluation (evaluate no subexpression until the value
is needed)
Has โ€œlist comprehensions,โ€ which allow it to deal with infinite
lists
Examples
Fibonacci numbers (illustrates function definitions with different
parameter forms)
fib 0 = 1
fib 1 = 1
fib (n + 2) = fib (n + 1) + fib n
ICS 313 - Fundamentals of Programming Languages 5
15.8 Haskell (continued)
Factorial (illustrates guards)
fact n
| n == 0 = 1
| n > 0 = n * fact (n - 1)
The special word otherwise can appear as a guard
List operations
List notation: Put elements in brackets
e.g., directions = [north, south, east, west]
Length: #
e.g., #directions is 4
Arithmetic series with the .. operator
e.g., [2, 4..10] is [2, 4, 6, 8, 10]
Catenation is with ++
e.g., [1, 3] ++ [5, 7] results in [1, 3, 5, 7]
CAR and CDR via the colon operator (as in Prolog)
e.g., 1:[3, 5, 7] results in [1, 3, 5, 7]
15.8 Haskell (continued)
Examples:
product [] = 1
product (a:x) = a * product x
fact n = product [1..n]
List comprehensions: set notation
e.g.,
[n * n | n โ† [1..20]]
defines a list of the squares of the first 20 positive integers
factors n = [i | i [1..n div 2],n mod i == 0]
This function computes all of the factors of its given parameter
Quicksort:
sort [] = []
sort (a:x) = sort [b | b โ† x; b <= a]
++ [a] ++
sort [b | b โ† x; b > a]
ICS 313 - Fundamentals of Programming Languages 6
15.8 Haskell (continued)
Lazy evaluation
Infinite lists
e.g.,
positives = [0..]
squares = [n * n | n โ† [0..]]
(only compute those that are necessary)
e.g.,
member squares 16
would return True
The member function could be written as:
member [] b = False
member (a:x) b = (a == b) || member x b
However, this would only work if the parameter to squares was
a perfect square; if not, it will keep generating them forever.
The following version will always work:
member2 (m:x) n
| m < n = member2 x n
| m == n = True
| otherwise = False
15.8 Haskell (continued)
Applications of Functional Languages:
LISP is used for artificial intelligence
Knowledge representation
Machine learning
Natural language processing
Modeling of speech and vision
Scheme is used to teach introductory programming at a significant
number of universities
Comparing Functional and Imperative Languages
Imperative Languages:
Efficient execution
Complex semantics
Complex syntax
Concurrency is programmer designed
Functional Languages:
Simple semantics
Simple syntax
Inefficient execution
Programs can automatically be made concurrent
Ad

More Related Content

What's hot (20)

Basic operators in matlab
Basic operators in matlabBasic operators in matlab
Basic operators in matlab
rishiteta
ย 
Introduction to matlab lecture 1 of 4
Introduction to matlab lecture 1 of 4Introduction to matlab lecture 1 of 4
Introduction to matlab lecture 1 of 4
Randa Elanwar
ย 
Matlab from Beginner to Expert
Matlab from Beginner to ExpertMatlab from Beginner to Expert
Matlab from Beginner to Expert
smart-ideas
ย 
Matlab Workshop Presentation
Matlab Workshop PresentationMatlab Workshop Presentation
Matlab Workshop Presentation
Jairo Maldonado-Contreras
ย 
Introduction to Matlab
Introduction to MatlabIntroduction to Matlab
Introduction to Matlab
Amr Rashed
ย 
Matlab practical and lab session
Matlab practical and lab sessionMatlab practical and lab session
Matlab practical and lab session
Dr. Krishna Mohbey
ย 
Matlab intro
Matlab introMatlab intro
Matlab intro
Chaitanya Banoth
ย 
Introduction to MatLab programming
Introduction to MatLab programmingIntroduction to MatLab programming
Introduction to MatLab programming
Damian T. Gordon
ย 
Matlab Overviiew
Matlab OverviiewMatlab Overviiew
Matlab Overviiew
Nazim Naeem
ย 
MATLAB BASICS
MATLAB BASICSMATLAB BASICS
MATLAB BASICS
butest
ย 
MATLAB - The Need to Know Basics
MATLAB - The Need to Know BasicsMATLAB - The Need to Know Basics
MATLAB - The Need to Know Basics
STEM Course Prep
ย 
Intro to Matlab programming
Intro to Matlab programmingIntro to Matlab programming
Intro to Matlab programming
Ahmed Moawad
ย 
Matlab 1(operations on_matrix)
Matlab 1(operations on_matrix)Matlab 1(operations on_matrix)
Matlab 1(operations on_matrix)
harman kaur
ย 
Ppt 2 d ploting k10998
Ppt 2 d ploting k10998Ppt 2 d ploting k10998
Ppt 2 d ploting k10998
Vinit Rajput
ย 
All About MATLAB
All About MATLABAll About MATLAB
All About MATLAB
Multisoft Virtual Academy
ย 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLAB
Sarah Hussein
ย 
Matlab solved problems
Matlab solved problemsMatlab solved problems
Matlab solved problems
Make Mannan
ย 
Matlab intro
Matlab introMatlab intro
Matlab intro
THEMASTERBLASTERSVID
ย 
Matlab basic and image
Matlab basic and imageMatlab basic and image
Matlab basic and image
Divyanshu Rasauria
ย 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
Mohan Raj
ย 
Basic operators in matlab
Basic operators in matlabBasic operators in matlab
Basic operators in matlab
rishiteta
ย 
Introduction to matlab lecture 1 of 4
Introduction to matlab lecture 1 of 4Introduction to matlab lecture 1 of 4
Introduction to matlab lecture 1 of 4
Randa Elanwar
ย 
Matlab from Beginner to Expert
Matlab from Beginner to ExpertMatlab from Beginner to Expert
Matlab from Beginner to Expert
smart-ideas
ย 
Introduction to Matlab
Introduction to MatlabIntroduction to Matlab
Introduction to Matlab
Amr Rashed
ย 
Matlab practical and lab session
Matlab practical and lab sessionMatlab practical and lab session
Matlab practical and lab session
Dr. Krishna Mohbey
ย 
Introduction to MatLab programming
Introduction to MatLab programmingIntroduction to MatLab programming
Introduction to MatLab programming
Damian T. Gordon
ย 
Matlab Overviiew
Matlab OverviiewMatlab Overviiew
Matlab Overviiew
Nazim Naeem
ย 
MATLAB BASICS
MATLAB BASICSMATLAB BASICS
MATLAB BASICS
butest
ย 
MATLAB - The Need to Know Basics
MATLAB - The Need to Know BasicsMATLAB - The Need to Know Basics
MATLAB - The Need to Know Basics
STEM Course Prep
ย 
Intro to Matlab programming
Intro to Matlab programmingIntro to Matlab programming
Intro to Matlab programming
Ahmed Moawad
ย 
Matlab 1(operations on_matrix)
Matlab 1(operations on_matrix)Matlab 1(operations on_matrix)
Matlab 1(operations on_matrix)
harman kaur
ย 
Ppt 2 d ploting k10998
Ppt 2 d ploting k10998Ppt 2 d ploting k10998
Ppt 2 d ploting k10998
Vinit Rajput
ย 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLAB
Sarah Hussein
ย 
Matlab solved problems
Matlab solved problemsMatlab solved problems
Matlab solved problems
Make Mannan
ย 
Matlab basic and image
Matlab basic and imageMatlab basic and image
Matlab basic and image
Divyanshu Rasauria
ย 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
Mohan Raj
ย 

Viewers also liked (9)

6 data types
6 data types6 data types
6 data types
jigeno
ย 
Access2007 m2
Access2007 m2Access2007 m2
Access2007 m2
jigeno
ย 
14 exception handling
14 exception handling14 exception handling
14 exception handling
jigeno
ย 
15 functional programming
15 functional programming15 functional programming
15 functional programming
jigeno
ย 
8 statement-level control structure
8 statement-level control structure8 statement-level control structure
8 statement-level control structure
jigeno
ย 
12 object oriented programming
12 object oriented programming12 object oriented programming
12 object oriented programming
jigeno
ย 
7 expressions and assignment statements
7 expressions and assignment statements7 expressions and assignment statements
7 expressions and assignment statements
jigeno
ย 
1 preliminaries
1 preliminaries1 preliminaries
1 preliminaries
jigeno
ย 
4 lexical and syntax analysis
4 lexical and syntax analysis4 lexical and syntax analysis
4 lexical and syntax analysis
jigeno
ย 
6 data types
6 data types6 data types
6 data types
jigeno
ย 
Access2007 m2
Access2007 m2Access2007 m2
Access2007 m2
jigeno
ย 
14 exception handling
14 exception handling14 exception handling
14 exception handling
jigeno
ย 
15 functional programming
15 functional programming15 functional programming
15 functional programming
jigeno
ย 
8 statement-level control structure
8 statement-level control structure8 statement-level control structure
8 statement-level control structure
jigeno
ย 
12 object oriented programming
12 object oriented programming12 object oriented programming
12 object oriented programming
jigeno
ย 
7 expressions and assignment statements
7 expressions and assignment statements7 expressions and assignment statements
7 expressions and assignment statements
jigeno
ย 
1 preliminaries
1 preliminaries1 preliminaries
1 preliminaries
jigeno
ย 
4 lexical and syntax analysis
4 lexical and syntax analysis4 lexical and syntax analysis
4 lexical and syntax analysis
jigeno
ย 
Ad

Similar to 15 functional programming (20)

OOPS Object oriented Programming PPT Tutorial
OOPS Object oriented Programming PPT TutorialOOPS Object oriented Programming PPT Tutorial
OOPS Object oriented Programming PPT Tutorial
amitnitpatna
ย 
LISP: Introduction to lisp
LISP: Introduction to lispLISP: Introduction to lisp
LISP: Introduction to lisp
DataminingTools Inc
ย 
LISP: Introduction To Lisp
LISP: Introduction To LispLISP: Introduction To Lisp
LISP: Introduction To Lisp
LISP Content
ย 
2301107049(Manikarthik).ppt.pptx functional programming and lis
2301107049(Manikarthik).ppt.pptx functional programming and lis2301107049(Manikarthik).ppt.pptx functional programming and lis
2301107049(Manikarthik).ppt.pptx functional programming and lis
kavipriyahari1980
ย 
Inroduction to r
Inroduction to rInroduction to r
Inroduction to r
manikanta361
ย 
Using Language Oriented Programming to Execute Computations on the GPU
Using Language Oriented Programming to Execute Computations on the GPUUsing Language Oriented Programming to Execute Computations on the GPU
Using Language Oriented Programming to Execute Computations on the GPU
Skills Matter
ย 
Programming in Scala - Lecture Two
Programming in Scala - Lecture TwoProgramming in Scala - Lecture Two
Programming in Scala - Lecture Two
Angelo Corsaro
ย 
Introduction to R for beginners
Introduction to R for beginnersIntroduction to R for beginners
Introduction to R for beginners
Abishek Purushothaman
ย 
Functions.docx
Functions.docxFunctions.docx
Functions.docx
VandanaGoyal21
ย 
1. Ch_1 SL_1_Intro to Matlab.pptx
1. Ch_1 SL_1_Intro to Matlab.pptx1. Ch_1 SL_1_Intro to Matlab.pptx
1. Ch_1 SL_1_Intro to Matlab.pptx
MOHAMMAD SAYDUL ALAM
ย 
Python programming: Anonymous functions, String operations
Python programming: Anonymous functions, String operationsPython programming: Anonymous functions, String operations
Python programming: Anonymous functions, String operations
Megha V
ย 
Unit 2 - Functions in python - Prof Jishnu M S
Unit 2 - Functions in python - Prof Jishnu M SUnit 2 - Functions in python - Prof Jishnu M S
Unit 2 - Functions in python - Prof Jishnu M S
jishnums10
ย 
Functional Programming Languages slidesslies.ppt
Functional Programming Languages slidesslies.pptFunctional Programming Languages slidesslies.ppt
Functional Programming Languages slidesslies.ppt
BikalAdhikari4
ย 
Functions in advanced programming
Functions in advanced programmingFunctions in advanced programming
Functions in advanced programming
VisnuDharsini
ย 
Automatic Task-based Code Generation for High Performance DSEL
Automatic Task-based Code Generation for High Performance DSELAutomatic Task-based Code Generation for High Performance DSEL
Automatic Task-based Code Generation for High Performance DSEL
Joel Falcou
ย 
User defined functions in matlab
User defined functions in  matlabUser defined functions in  matlab
User defined functions in matlab
Infinity Tech Solutions
ย 
Matlab Manual
Matlab ManualMatlab Manual
Matlab Manual
Thesis Scientist Private Limited
ย 
R basics
R basicsR basics
R basics
Sagun Baijal
ย 
Programming Languages - Functional Programming Paper
Programming Languages - Functional Programming PaperProgramming Languages - Functional Programming Paper
Programming Languages - Functional Programming Paper
Shreya Chakrabarti
ย 
Functions in C++
Functions in C++Functions in C++
Functions in C++
home
ย 
OOPS Object oriented Programming PPT Tutorial
OOPS Object oriented Programming PPT TutorialOOPS Object oriented Programming PPT Tutorial
OOPS Object oriented Programming PPT Tutorial
amitnitpatna
ย 
LISP: Introduction to lisp
LISP: Introduction to lispLISP: Introduction to lisp
LISP: Introduction to lisp
DataminingTools Inc
ย 
LISP: Introduction To Lisp
LISP: Introduction To LispLISP: Introduction To Lisp
LISP: Introduction To Lisp
LISP Content
ย 
2301107049(Manikarthik).ppt.pptx functional programming and lis
2301107049(Manikarthik).ppt.pptx functional programming and lis2301107049(Manikarthik).ppt.pptx functional programming and lis
2301107049(Manikarthik).ppt.pptx functional programming and lis
kavipriyahari1980
ย 
Inroduction to r
Inroduction to rInroduction to r
Inroduction to r
manikanta361
ย 
Using Language Oriented Programming to Execute Computations on the GPU
Using Language Oriented Programming to Execute Computations on the GPUUsing Language Oriented Programming to Execute Computations on the GPU
Using Language Oriented Programming to Execute Computations on the GPU
Skills Matter
ย 
Programming in Scala - Lecture Two
Programming in Scala - Lecture TwoProgramming in Scala - Lecture Two
Programming in Scala - Lecture Two
Angelo Corsaro
ย 
Introduction to R for beginners
Introduction to R for beginnersIntroduction to R for beginners
Introduction to R for beginners
Abishek Purushothaman
ย 
Functions.docx
Functions.docxFunctions.docx
Functions.docx
VandanaGoyal21
ย 
1. Ch_1 SL_1_Intro to Matlab.pptx
1. Ch_1 SL_1_Intro to Matlab.pptx1. Ch_1 SL_1_Intro to Matlab.pptx
1. Ch_1 SL_1_Intro to Matlab.pptx
MOHAMMAD SAYDUL ALAM
ย 
Python programming: Anonymous functions, String operations
Python programming: Anonymous functions, String operationsPython programming: Anonymous functions, String operations
Python programming: Anonymous functions, String operations
Megha V
ย 
Unit 2 - Functions in python - Prof Jishnu M S
Unit 2 - Functions in python - Prof Jishnu M SUnit 2 - Functions in python - Prof Jishnu M S
Unit 2 - Functions in python - Prof Jishnu M S
jishnums10
ย 
Functional Programming Languages slidesslies.ppt
Functional Programming Languages slidesslies.pptFunctional Programming Languages slidesslies.ppt
Functional Programming Languages slidesslies.ppt
BikalAdhikari4
ย 
Functions in advanced programming
Functions in advanced programmingFunctions in advanced programming
Functions in advanced programming
VisnuDharsini
ย 
Automatic Task-based Code Generation for High Performance DSEL
Automatic Task-based Code Generation for High Performance DSELAutomatic Task-based Code Generation for High Performance DSEL
Automatic Task-based Code Generation for High Performance DSEL
Joel Falcou
ย 
User defined functions in matlab
User defined functions in  matlabUser defined functions in  matlab
User defined functions in matlab
Infinity Tech Solutions
ย 
Programming Languages - Functional Programming Paper
Programming Languages - Functional Programming PaperProgramming Languages - Functional Programming Paper
Programming Languages - Functional Programming Paper
Shreya Chakrabarti
ย 
Functions in C++
Functions in C++Functions in C++
Functions in C++
home
ย 
Ad

More from jigeno (11)

Access2007 part1
Access2007 part1Access2007 part1
Access2007 part1
jigeno
ย 
Basic introduction to ms access
Basic introduction to ms accessBasic introduction to ms access
Basic introduction to ms access
jigeno
ย 
Bsit1
Bsit1Bsit1
Bsit1
jigeno
ย 
16 logical programming
16 logical programming16 logical programming
16 logical programming
jigeno
ย 
13 concurrency
13 concurrency13 concurrency
13 concurrency
jigeno
ย 
11 abstract data types
11 abstract data types11 abstract data types
11 abstract data types
jigeno
ย 
9 subprograms
9 subprograms9 subprograms
9 subprograms
jigeno
ย 
5 names
5 names5 names
5 names
jigeno
ย 
3 describing syntax and semantics
3 describing syntax and semantics3 describing syntax and semantics
3 describing syntax and semantics
jigeno
ย 
2 evolution of the major programming languages
2 evolution of the major programming languages2 evolution of the major programming languages
2 evolution of the major programming languages
jigeno
ย 
Access2007 m1
Access2007 m1Access2007 m1
Access2007 m1
jigeno
ย 
Access2007 part1
Access2007 part1Access2007 part1
Access2007 part1
jigeno
ย 
Basic introduction to ms access
Basic introduction to ms accessBasic introduction to ms access
Basic introduction to ms access
jigeno
ย 
Bsit1
Bsit1Bsit1
Bsit1
jigeno
ย 
16 logical programming
16 logical programming16 logical programming
16 logical programming
jigeno
ย 
13 concurrency
13 concurrency13 concurrency
13 concurrency
jigeno
ย 
11 abstract data types
11 abstract data types11 abstract data types
11 abstract data types
jigeno
ย 
9 subprograms
9 subprograms9 subprograms
9 subprograms
jigeno
ย 
5 names
5 names5 names
5 names
jigeno
ย 
3 describing syntax and semantics
3 describing syntax and semantics3 describing syntax and semantics
3 describing syntax and semantics
jigeno
ย 
2 evolution of the major programming languages
2 evolution of the major programming languages2 evolution of the major programming languages
2 evolution of the major programming languages
jigeno
ย 
Access2007 m1
Access2007 m1Access2007 m1
Access2007 m1
jigeno
ย 

Recently uploaded (20)

How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
ย 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
ย 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
ย 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
ย 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
ย 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
ย 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
ย 
Drupalcamp Finland โ€“ Measuring Front-end Energy Consumption
Drupalcamp Finland โ€“ Measuring Front-end Energy ConsumptionDrupalcamp Finland โ€“ Measuring Front-end Energy Consumption
Drupalcamp Finland โ€“ Measuring Front-end Energy Consumption
Exove
ย 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
ย 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
ย 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
ย 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
ย 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
ย 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
ย 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
ย 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
ย 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
ย 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
ย 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
ย 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
ย 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
ย 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
ย 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
ย 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
ย 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
ย 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
ย 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
ย 
Drupalcamp Finland โ€“ Measuring Front-end Energy Consumption
Drupalcamp Finland โ€“ Measuring Front-end Energy ConsumptionDrupalcamp Finland โ€“ Measuring Front-end Energy Consumption
Drupalcamp Finland โ€“ Measuring Front-end Energy Consumption
Exove
ย 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
ย 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
ย 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
ย 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
ย 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
ย 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
ย 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
ย 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
ย 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
ย 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
ย 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
ย 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
ย 

15 functional programming

  • 1. ICS 313 - Fundamentals of Programming Languages 1 15. Functional Programming 15.1 Introduction The design of the imperative languages is based directly on the von Neumann architecture Efficiency is the primary concern, rather than the suitability of the language for software development The design of the functional languages is based on mathematical functions A solid theoretical basis that is also closer to the user, but relatively unconcerned with the architecture of the machines on which programs will run
  • 2. ICS 313 - Fundamentals of Programming Languages 2 15.2 Mathematical Functions A mathematical function is a mapping of members of one set, called the domain set, to another set, called the range set A lambda expression specifies the parameter(s) and the mapping of a function in the following form ฮป(x) x * x * x for the function cube (x) = x * x * x Lambda expressions describe nameless functions Lambda expressions are applied to parameter(s) by placing the parameter(s) after the expression e.g. (ฮป(x) x * x * x)(3) which evaluates to 27 15.2 Mathematical Functions (continued) Functional Forms A higher-order function, or functional form, is one that either takes functions as parameters or yields a function as its result, or both Function Composition A functional form that takes two functions as parameters and yields a function whose result is a function whose value is the first actual parameter function applied to the result of the application of the second Form: h๏€  โ‰ก ๏€ f ยฐ g which means h (x) โ‰ก ๏€ f ( g ( x))
  • 3. ICS 313 - Fundamentals of Programming Languages 3 15.2 Mathematical Functions (continued) Construction A functional form that takes a list of functions as parameters and yields a list of the results of applying each of its parameter functions to a given parameter Form: [f, g] For f (x) โ‰ก x * x * x and g (x) โ‰ก x + 3, [f, g] (4) yields (64, 7) Apply-to-all A functional form that takes a single function as a parameter and yields a list of values obtained by applying the given function to each element of a list of parameters Form: ฮฑ For h (x) โ‰ก ๏€ x * x * x ฮฑ ๏€ ( h, (3, 2, 4)) yields (27, 8, 64) 15.3 Fundamentals of Functional Programming Languages The objective of the design of a FPL is to mimic mathematical functions to the greatest extent possible The basic process of computation is fundamentally different in a FPL than in an imperative language In an imperative language, operations are done and the results are stored in variables for later use Management of variables is a constant concern and source of complexity for imperative programming In an FPL, variables are not necessary, as is the case in mathematics In an FPL, the evaluation of a function always produces the same result given the same parameters This is called referential transparency
  • 4. ICS 313 - Fundamentals of Programming Languages 4 Functional Programming Languages LISP Lambda notation is used to specify functions and function definitions, function applications, and data all have the same form Scheme A mid-1970s dialect of LISP, designed to be a cleaner, more modern, and simpler version than the contemporary dialects of LISP COMMON LISP A combination of many of the features of the popular dialects of LISP around in the early 1980s ML A static-scoped functional language with syntax that is closer to Pascal than to LISP Haskell Similar to ML (syntax, static scoped, strongly typed, type inferencing) Different from ML (and most other functional languages) in that it is PURELY functional (e.g., no variables, no assignment statements, and no side effects of any kind) 15.8 Haskell Most Important Features Uses lazy evaluation (evaluate no subexpression until the value is needed) Has โ€œlist comprehensions,โ€ which allow it to deal with infinite lists Examples Fibonacci numbers (illustrates function definitions with different parameter forms) fib 0 = 1 fib 1 = 1 fib (n + 2) = fib (n + 1) + fib n
  • 5. ICS 313 - Fundamentals of Programming Languages 5 15.8 Haskell (continued) Factorial (illustrates guards) fact n | n == 0 = 1 | n > 0 = n * fact (n - 1) The special word otherwise can appear as a guard List operations List notation: Put elements in brackets e.g., directions = [north, south, east, west] Length: # e.g., #directions is 4 Arithmetic series with the .. operator e.g., [2, 4..10] is [2, 4, 6, 8, 10] Catenation is with ++ e.g., [1, 3] ++ [5, 7] results in [1, 3, 5, 7] CAR and CDR via the colon operator (as in Prolog) e.g., 1:[3, 5, 7] results in [1, 3, 5, 7] 15.8 Haskell (continued) Examples: product [] = 1 product (a:x) = a * product x fact n = product [1..n] List comprehensions: set notation e.g., [n * n | n โ† [1..20]] defines a list of the squares of the first 20 positive integers factors n = [i | i [1..n div 2],n mod i == 0] This function computes all of the factors of its given parameter Quicksort: sort [] = [] sort (a:x) = sort [b | b โ† x; b <= a] ++ [a] ++ sort [b | b โ† x; b > a]
  • 6. ICS 313 - Fundamentals of Programming Languages 6 15.8 Haskell (continued) Lazy evaluation Infinite lists e.g., positives = [0..] squares = [n * n | n โ† [0..]] (only compute those that are necessary) e.g., member squares 16 would return True The member function could be written as: member [] b = False member (a:x) b = (a == b) || member x b However, this would only work if the parameter to squares was a perfect square; if not, it will keep generating them forever. The following version will always work: member2 (m:x) n | m < n = member2 x n | m == n = True | otherwise = False 15.8 Haskell (continued) Applications of Functional Languages: LISP is used for artificial intelligence Knowledge representation Machine learning Natural language processing Modeling of speech and vision Scheme is used to teach introductory programming at a significant number of universities Comparing Functional and Imperative Languages Imperative Languages: Efficient execution Complex semantics Complex syntax Concurrency is programmer designed Functional Languages: Simple semantics Simple syntax Inefficient execution Programs can automatically be made concurrent