SlideShare a Scribd company logo
1
Elements of Functional Programming
2
A LITTLE LANGUAGE OF EXPRESSIONS
•The little language ----Little QuiltLittle Quilt:
•small enough to permit a short description
•different enough to require description
•representative enough to make description worthwhile
• Constructs in Little Quilt are expressions denoting
geometric objects call quilts:quilts:
3
A LITTLE LANGUAGE OF EXPRESSIONS
•What Does Little Quilt Manipulate?
•Little Quilt manipulates geometric objects with height,
width and texture
• Basic Value and Operations:
•The two primitive objects in the language are the
square piece.
The earliest programming languages
began with only integers and reals
4
A LITTLE LANGUAGE OF EXPRESSIONS
•The operation are specified by the following rules:
•A quilt is one of the primitive piece, or
•It is formed by turning a quilt clockwise 90°, or
•it is formed by sewing a quilt to the right of another
quilt of equal height.
•Nothing else is a quilt.
5
A LITTLE LANGUAGE OF EXPRESSIONS
• Constants:
• Names for basic values: the pieces be called aa and bb
•Names of operations: the operations be called turnturn and sewsew. (like
the picture on the previous slide)
•now that we have chosen the built-in object and operations (a,b, turn,
sew) expressions can be formed
•<expression>::=a | b | turn(<expression>)
• | sew (<expression>,<expression>)
6
TYPES: VALUES AND OPERATIONS
• A typetype consists of a set of elements called valuesvalues together
with a set of function called operationsoperations.
•<type-expression>::=<type-name>
| <type-expression> <type-expression>
| <type-expression>*<type-expression>
|<type-expression> list
•A type expression can be a type name, or it can denote a
function, product, or list type. (operations are ->, * and list)
7
TYPES: VALUES AND OPERATIONS
• Basic Types:
•A type is basic if its values are atomic
•the values are treated as whole elements, with no internal
structure.
•Example: the boolean values in the set { true, false}
•Operations on Basic Values:
• The only operation defined for all basic types is a
comparison for equality (have no internal structure)
8
TYPES: VALUES AND OPERATIONS
• Products of Types: The product A*B consists of ordered
pairs written as (a, b)
•Operations on Pairs
•A pair is constructed from a and b by writing (a, b)
•Associated with pairs are operations called projectionprojection
functionsfunctions to extract the first and second elements from a
pair
•Projection functionsProjection functions can be defined:
•fun first(x,y) = x;
•fun second( x, y)=y;
9
TYPES: VALUES AND OPERATIONS
• Lists of Elements:
•A list is a finite-length sequence of elements
•Type A list consists of all lists of elements, where each
element belongs to type A.
•Example:
•int list consists of all lists of integers
•[1,2,3] is a list of three integers 1, 2, and 3.
•[“red”, “white”, “blue”] is a list of three strings
10
TYPES: VALUES AND OPERATIONS
•Operations on Lists
•List-manipulation programs must be prepared to
construct and inspect lists of any length.
•Operations on list from ML:
•null(x) True if x is the empty list, false otherwise.
•hd(x) The first or head element of list x.
•tl(x) The tail or rest of the list after the first element
is removed.
•a::x Construct a list with head a and tail x.
Cons operator
11
TYPES: VALUES AND OPERATIONS
•Types in ML
Predeclared basic types of ML.
Type Name Values Operations
_____________________________________________________
boolean bool true,false =,<>,…
integer int …,-1,0,1,2,… =,<>,<,+,*,div,mod,…
real real …,0.0,…,3.14,.. =,<>,<,+,*,/,…
string string “foo”,””quoted”” =,<>,…
_____________________________________________________
•New basic types can be defined as needed by a datatype
declaration
•Example: datatype direction = ne | se |sw| nw;
12
FUNCTION DECLARATIONS
• Functions as Algorithms
A function declaration has three parts:
•The name of the declared function
•The parameters of the function
•A rule for computing a result from the parameters
13
FUNCTION DECLARATIONS
• Syntax of Function Declarations and Applications
•The basic syntax for function declarations is
fun <name><formal-parameter> = <body>
•<name> is the function name
•<formal-parameter> is a parameter name
•<body> is an expression to be evaluated
•fun successor n = n +1;
•fun successor (n)= n +1;
() are optional
14
FUNCTION DECLARATIONS
• The use of a function within an expression is called an
applicationapplication of the function.
•Prefix notation is the rule for the application of
declared function
•<name><actual-parameter>
•<name> is the function name
•<actual-parameter> is an expression
corresponding to the parameter name in the
declaration of the function
•Example: successor(2+3)
15
FUNCTION DECLARATIONS
• Recursive Functions -- A function f is recursive if its
body contains an application of f.
•Example1:
•Function len counts the number of elements in a list
•fun len(x)=
if null(x) then 0 else 1 + len(tl(x))
16
Approaches to Expression Evaluation
•Innermost Evaluation
•Outermost Evaluation
•Selective Evaluation
•Evaluation of Recursive Functions
•Short-Circuit Evaluation
17
Type Checking
Type Inference:
•Wherever possible ,ML infers the type of an expression.An error
is reported if the type of an expression cannot be inferred.
•If E and F have type int then E+F also has type int .
•In general,
If f is a function of type A -->B , and a has type A,
then f(a) has type B.
18
Type Names and Type Equivalence
Two type expressions are said to be structurally equivalent if and
only if they are equivalent under the following rules:
1. A type name is structurally equivalent to itself.
2. Two type expressions are structurally equivalent if they are
formed by
applying the same type constructor to structurally
equivalent types.
3. After a type declaration, type n = T ,the type name n is
structurally equivalent to T .
19
Overloading:Multiple Meanings
A symbol is said to be overloaded if it has different meanings in
different contexts.Family operator symbols like + and * are
overloaded.
e.g. 2+2 here + is of type int
2.5+3.6 here + is of type real.
ML cannot resolve overloading in fun add(x,y) = x+y ;
Explicit types can be used to resolve overloading.
fun add(x,y): int =x+y ;
PRESENTED BY
SAJJAD ALI P M
CS –B ,34
20
THANK YOU!!
21
Ad

More Related Content

What's hot (20)

Basic data types in python
Basic data types in pythonBasic data types in python
Basic data types in python
sunilchute1
 
Values and Data types in python
Values and Data types in pythonValues and Data types in python
Values and Data types in python
Jothi Thilaga P
 
Getting started with c++
Getting started with c++Getting started with c++
Getting started with c++
K Durga Prasad
 
Programming construction tools
Programming construction toolsProgramming construction tools
Programming construction tools
sunilchute1
 
Frequently asked questions in c
Frequently asked questions in cFrequently asked questions in c
Frequently asked questions in c
David Livingston J
 
Chapter 2.datatypes and operators
Chapter 2.datatypes and operatorsChapter 2.datatypes and operators
Chapter 2.datatypes and operators
Jasleen Kaur (Chandigarh University)
 
LISP: Input And Output
LISP: Input And OutputLISP: Input And Output
LISP: Input And Output
DataminingTools Inc
 
Lec4slides
Lec4slidesLec4slides
Lec4slides
shawiz
 
Frequently asked questions in c
Frequently asked questions in cFrequently asked questions in c
Frequently asked questions in c
David Livingston J
 
Input processing and output in Python
Input processing and output in PythonInput processing and output in Python
Input processing and output in Python
Raajendra M
 
Python revision tour II
Python revision tour IIPython revision tour II
Python revision tour II
Mr. Vikram Singh Slathia
 
Basic of c &c++
Basic of c &c++Basic of c &c++
Basic of c &c++
guptkashish
 
C++
C++C++
C++
AL- AMIN
 
Token and operators
Token and operatorsToken and operators
Token and operators
Samsil Arefin
 
Python second ppt
Python second pptPython second ppt
Python second ppt
RaginiJain21
 
Lec9
Lec9Lec9
Lec9
kapil078
 
Learn C LANGUAGE at ASIT
Learn C LANGUAGE at ASITLearn C LANGUAGE at ASIT
Learn C LANGUAGE at ASIT
ASIT
 
M C6java2
M C6java2M C6java2
M C6java2
mbruggen
 
Ch5a
Ch5aCh5a
Ch5a
kinnarshah8888
 
Data types and Operators
Data types and OperatorsData types and Operators
Data types and Operators
raksharao
 

Viewers also liked (13)

Object oriented-programming-vs-procedural-programming
Object oriented-programming-vs-procedural-programmingObject oriented-programming-vs-procedural-programming
Object oriented-programming-vs-procedural-programming
kukurmutta
 
Procedural vs. object oriented programming
Procedural vs. object oriented programmingProcedural vs. object oriented programming
Procedural vs. object oriented programming
Haris Bin Zahid
 
Ppl pdf
Ppl pdfPpl pdf
Ppl pdf
Phoenix helicopter Academy
 
Ak procedural vs oop
Ak procedural vs oopAk procedural vs oop
Ak procedural vs oop
Abhishek Kumar
 
diffrence between procedure oriented programming & object oriented programmin...
diffrence between procedure oriented programming & object oriented programmin...diffrence between procedure oriented programming & object oriented programmin...
diffrence between procedure oriented programming & object oriented programmin...
nihar joshi
 
Prgramming paradigms
Prgramming paradigmsPrgramming paradigms
Prgramming paradigms
Anirudh Chauhan
 
Scala: functional programming for the imperative mind
Scala: functional programming for the imperative mindScala: functional programming for the imperative mind
Scala: functional programming for the imperative mind
Sander Mak (@Sander_Mak)
 
operating system structure
operating system structureoperating system structure
operating system structure
Waseem Ud Din Farooqui
 
Functional Programming Fundamentals
Functional Programming FundamentalsFunctional Programming Fundamentals
Functional Programming Fundamentals
Shahriar Hyder
 
Introduction to Procedural Programming in C++
Introduction to Procedural Programming in C++Introduction to Procedural Programming in C++
Introduction to Procedural Programming in C++
Salahaddin University-Erbil
 
Oops ppt
Oops pptOops ppt
Oops ppt
abhayjuneja
 
Functional Programming Patterns (BuildStuff '14)
Functional Programming Patterns (BuildStuff '14)Functional Programming Patterns (BuildStuff '14)
Functional Programming Patterns (BuildStuff '14)
Scott Wlaschin
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts
thinkphp
 
Object oriented-programming-vs-procedural-programming
Object oriented-programming-vs-procedural-programmingObject oriented-programming-vs-procedural-programming
Object oriented-programming-vs-procedural-programming
kukurmutta
 
Procedural vs. object oriented programming
Procedural vs. object oriented programmingProcedural vs. object oriented programming
Procedural vs. object oriented programming
Haris Bin Zahid
 
diffrence between procedure oriented programming & object oriented programmin...
diffrence between procedure oriented programming & object oriented programmin...diffrence between procedure oriented programming & object oriented programmin...
diffrence between procedure oriented programming & object oriented programmin...
nihar joshi
 
Scala: functional programming for the imperative mind
Scala: functional programming for the imperative mindScala: functional programming for the imperative mind
Scala: functional programming for the imperative mind
Sander Mak (@Sander_Mak)
 
Functional Programming Fundamentals
Functional Programming FundamentalsFunctional Programming Fundamentals
Functional Programming Fundamentals
Shahriar Hyder
 
Functional Programming Patterns (BuildStuff '14)
Functional Programming Patterns (BuildStuff '14)Functional Programming Patterns (BuildStuff '14)
Functional Programming Patterns (BuildStuff '14)
Scott Wlaschin
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts
thinkphp
 
Ad

Similar to Elements of functional programming (20)

MODULE-2.pptx
MODULE-2.pptxMODULE-2.pptx
MODULE-2.pptx
ASRPANDEY
 
Acm aleppo cpc training sixth session
Acm aleppo cpc training sixth sessionAcm aleppo cpc training sixth session
Acm aleppo cpc training sixth session
Ahmad Bashar Eter
 
An Introduction : Python
An Introduction : PythonAn Introduction : Python
An Introduction : Python
Raghu Kumar
 
12TypeSystem.pdf
12TypeSystem.pdf12TypeSystem.pdf
12TypeSystem.pdf
MdAshik35
 
Review 2Pygame made using python programming
Review 2Pygame made using python programmingReview 2Pygame made using python programming
Review 2Pygame made using python programming
ithepacer
 
Grade XI - Computer science Data Handling in Python
Grade XI - Computer science Data Handling in PythonGrade XI - Computer science Data Handling in Python
Grade XI - Computer science Data Handling in Python
vidyuthno1
 
unit1 python.pptx
unit1 python.pptxunit1 python.pptx
unit1 python.pptx
TKSanthoshRao
 
Programming with Python - Week 3
Programming with Python - Week 3Programming with Python - Week 3
Programming with Python - Week 3
Ahmet Bulut
 
An Introduction To Python - Tables, List Algorithms
An Introduction To Python - Tables, List AlgorithmsAn Introduction To Python - Tables, List Algorithms
An Introduction To Python - Tables, List Algorithms
Blue Elephant Consulting
 
Python programming
Python programmingPython programming
Python programming
sirikeshava
 
Demystifying Shapeless
Demystifying Shapeless Demystifying Shapeless
Demystifying Shapeless
Jared Roesch
 
Python Revision Tour.pptx class 12 python notes
Python Revision Tour.pptx class 12 python notesPython Revision Tour.pptx class 12 python notes
Python Revision Tour.pptx class 12 python notes
student164700
 
Python Basics it will teach you about data types
Python Basics it will teach you about data typesPython Basics it will teach you about data types
Python Basics it will teach you about data types
NimitSinghal2
 
Python for Data Science function third module ppt.pptx
Python for Data Science  function third module ppt.pptxPython for Data Science  function third module ppt.pptx
Python for Data Science function third module ppt.pptx
bmit1
 
Python Data-Types
Python Data-TypesPython Data-Types
Python Data-Types
Akhil Kaushik
 
Presentation on python data type
Presentation on python data typePresentation on python data type
Presentation on python data type
swati kushwaha
 
An Introduction to Tuple List Dictionary in Python
An Introduction to Tuple List Dictionary in PythonAn Introduction to Tuple List Dictionary in Python
An Introduction to Tuple List Dictionary in Python
yashar Aliabasi
 
introduction2_programming slides briefly exolained
introduction2_programming slides briefly exolainedintroduction2_programming slides briefly exolained
introduction2_programming slides briefly exolained
RumaSinha8
 
A File is a collection of data stored in the secondary memory. So far data wa...
A File is a collection of data stored in the secondary memory. So far data wa...A File is a collection of data stored in the secondary memory. So far data wa...
A File is a collection of data stored in the secondary memory. So far data wa...
bhargavi804095
 
Chapter02.PPT
Chapter02.PPTChapter02.PPT
Chapter02.PPT
Chaitanya Jambotkar
 
MODULE-2.pptx
MODULE-2.pptxMODULE-2.pptx
MODULE-2.pptx
ASRPANDEY
 
Acm aleppo cpc training sixth session
Acm aleppo cpc training sixth sessionAcm aleppo cpc training sixth session
Acm aleppo cpc training sixth session
Ahmad Bashar Eter
 
An Introduction : Python
An Introduction : PythonAn Introduction : Python
An Introduction : Python
Raghu Kumar
 
12TypeSystem.pdf
12TypeSystem.pdf12TypeSystem.pdf
12TypeSystem.pdf
MdAshik35
 
Review 2Pygame made using python programming
Review 2Pygame made using python programmingReview 2Pygame made using python programming
Review 2Pygame made using python programming
ithepacer
 
Grade XI - Computer science Data Handling in Python
Grade XI - Computer science Data Handling in PythonGrade XI - Computer science Data Handling in Python
Grade XI - Computer science Data Handling in Python
vidyuthno1
 
Programming with Python - Week 3
Programming with Python - Week 3Programming with Python - Week 3
Programming with Python - Week 3
Ahmet Bulut
 
An Introduction To Python - Tables, List Algorithms
An Introduction To Python - Tables, List AlgorithmsAn Introduction To Python - Tables, List Algorithms
An Introduction To Python - Tables, List Algorithms
Blue Elephant Consulting
 
Python programming
Python programmingPython programming
Python programming
sirikeshava
 
Demystifying Shapeless
Demystifying Shapeless Demystifying Shapeless
Demystifying Shapeless
Jared Roesch
 
Python Revision Tour.pptx class 12 python notes
Python Revision Tour.pptx class 12 python notesPython Revision Tour.pptx class 12 python notes
Python Revision Tour.pptx class 12 python notes
student164700
 
Python Basics it will teach you about data types
Python Basics it will teach you about data typesPython Basics it will teach you about data types
Python Basics it will teach you about data types
NimitSinghal2
 
Python for Data Science function third module ppt.pptx
Python for Data Science  function third module ppt.pptxPython for Data Science  function third module ppt.pptx
Python for Data Science function third module ppt.pptx
bmit1
 
Presentation on python data type
Presentation on python data typePresentation on python data type
Presentation on python data type
swati kushwaha
 
An Introduction to Tuple List Dictionary in Python
An Introduction to Tuple List Dictionary in PythonAn Introduction to Tuple List Dictionary in Python
An Introduction to Tuple List Dictionary in Python
yashar Aliabasi
 
introduction2_programming slides briefly exolained
introduction2_programming slides briefly exolainedintroduction2_programming slides briefly exolained
introduction2_programming slides briefly exolained
RumaSinha8
 
A File is a collection of data stored in the secondary memory. So far data wa...
A File is a collection of data stored in the secondary memory. So far data wa...A File is a collection of data stored in the secondary memory. So far data wa...
A File is a collection of data stored in the secondary memory. So far data wa...
bhargavi804095
 
Ad

Recently uploaded (20)

ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITYADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ijscai
 
The Gaussian Process Modeling Module in UQLab
The Gaussian Process Modeling Module in UQLabThe Gaussian Process Modeling Module in UQLab
The Gaussian Process Modeling Module in UQLab
Journal of Soft Computing in Civil Engineering
 
π0.5: a Vision-Language-Action Model with Open-World Generalization
π0.5: a Vision-Language-Action Model with Open-World Generalizationπ0.5: a Vision-Language-Action Model with Open-World Generalization
π0.5: a Vision-Language-Action Model with Open-World Generalization
NABLAS株式会社
 
AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)
Vəhid Gəruslu
 
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design ThinkingDT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DhruvChotaliya2
 
Artificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptxArtificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptx
aditichinar
 
Introduction to FLUID MECHANICS & KINEMATICS
Introduction to FLUID MECHANICS &  KINEMATICSIntroduction to FLUID MECHANICS &  KINEMATICS
Introduction to FLUID MECHANICS & KINEMATICS
narayanaswamygdas
 
fluke dealers in bangalore..............
fluke dealers in bangalore..............fluke dealers in bangalore..............
fluke dealers in bangalore..............
Haresh Vaswani
 
Value Stream Mapping Worskshops for Intelligent Continuous Security
Value Stream Mapping Worskshops for Intelligent Continuous SecurityValue Stream Mapping Worskshops for Intelligent Continuous Security
Value Stream Mapping Worskshops for Intelligent Continuous Security
Marc Hornbeek
 
introduction to machine learining for beginers
introduction to machine learining for beginersintroduction to machine learining for beginers
introduction to machine learining for beginers
JoydebSheet
 
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Journal of Soft Computing in Civil Engineering
 
Smart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineeringSmart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineering
rushikeshnavghare94
 
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
charlesdick1345
 
Oil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdfOil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdf
M7md3li2
 
theory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptxtheory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptx
sanchezvanessa7896
 
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E..."Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
Infopitaara
 
Machine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptxMachine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptx
rajeswari89780
 
International Journal of Distributed and Parallel systems (IJDPS)
International Journal of Distributed and Parallel systems (IJDPS)International Journal of Distributed and Parallel systems (IJDPS)
International Journal of Distributed and Parallel systems (IJDPS)
samueljackson3773
 
IntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdfIntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdf
Luiz Carneiro
 
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptxLidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
RishavKumar530754
 
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITYADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ijscai
 
π0.5: a Vision-Language-Action Model with Open-World Generalization
π0.5: a Vision-Language-Action Model with Open-World Generalizationπ0.5: a Vision-Language-Action Model with Open-World Generalization
π0.5: a Vision-Language-Action Model with Open-World Generalization
NABLAS株式会社
 
AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)
Vəhid Gəruslu
 
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design ThinkingDT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DhruvChotaliya2
 
Artificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptxArtificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptx
aditichinar
 
Introduction to FLUID MECHANICS & KINEMATICS
Introduction to FLUID MECHANICS &  KINEMATICSIntroduction to FLUID MECHANICS &  KINEMATICS
Introduction to FLUID MECHANICS & KINEMATICS
narayanaswamygdas
 
fluke dealers in bangalore..............
fluke dealers in bangalore..............fluke dealers in bangalore..............
fluke dealers in bangalore..............
Haresh Vaswani
 
Value Stream Mapping Worskshops for Intelligent Continuous Security
Value Stream Mapping Worskshops for Intelligent Continuous SecurityValue Stream Mapping Worskshops for Intelligent Continuous Security
Value Stream Mapping Worskshops for Intelligent Continuous Security
Marc Hornbeek
 
introduction to machine learining for beginers
introduction to machine learining for beginersintroduction to machine learining for beginers
introduction to machine learining for beginers
JoydebSheet
 
Smart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineeringSmart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineering
rushikeshnavghare94
 
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
charlesdick1345
 
Oil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdfOil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdf
M7md3li2
 
theory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptxtheory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptx
sanchezvanessa7896
 
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E..."Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
Infopitaara
 
Machine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptxMachine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptx
rajeswari89780
 
International Journal of Distributed and Parallel systems (IJDPS)
International Journal of Distributed and Parallel systems (IJDPS)International Journal of Distributed and Parallel systems (IJDPS)
International Journal of Distributed and Parallel systems (IJDPS)
samueljackson3773
 
IntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdfIntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdf
Luiz Carneiro
 
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptxLidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
RishavKumar530754
 

Elements of functional programming

  • 2. 2 A LITTLE LANGUAGE OF EXPRESSIONS •The little language ----Little QuiltLittle Quilt: •small enough to permit a short description •different enough to require description •representative enough to make description worthwhile • Constructs in Little Quilt are expressions denoting geometric objects call quilts:quilts:
  • 3. 3 A LITTLE LANGUAGE OF EXPRESSIONS •What Does Little Quilt Manipulate? •Little Quilt manipulates geometric objects with height, width and texture • Basic Value and Operations: •The two primitive objects in the language are the square piece. The earliest programming languages began with only integers and reals
  • 4. 4 A LITTLE LANGUAGE OF EXPRESSIONS •The operation are specified by the following rules: •A quilt is one of the primitive piece, or •It is formed by turning a quilt clockwise 90°, or •it is formed by sewing a quilt to the right of another quilt of equal height. •Nothing else is a quilt.
  • 5. 5 A LITTLE LANGUAGE OF EXPRESSIONS • Constants: • Names for basic values: the pieces be called aa and bb •Names of operations: the operations be called turnturn and sewsew. (like the picture on the previous slide) •now that we have chosen the built-in object and operations (a,b, turn, sew) expressions can be formed •<expression>::=a | b | turn(<expression>) • | sew (<expression>,<expression>)
  • 6. 6 TYPES: VALUES AND OPERATIONS • A typetype consists of a set of elements called valuesvalues together with a set of function called operationsoperations. •<type-expression>::=<type-name> | <type-expression> <type-expression> | <type-expression>*<type-expression> |<type-expression> list •A type expression can be a type name, or it can denote a function, product, or list type. (operations are ->, * and list)
  • 7. 7 TYPES: VALUES AND OPERATIONS • Basic Types: •A type is basic if its values are atomic •the values are treated as whole elements, with no internal structure. •Example: the boolean values in the set { true, false} •Operations on Basic Values: • The only operation defined for all basic types is a comparison for equality (have no internal structure)
  • 8. 8 TYPES: VALUES AND OPERATIONS • Products of Types: The product A*B consists of ordered pairs written as (a, b) •Operations on Pairs •A pair is constructed from a and b by writing (a, b) •Associated with pairs are operations called projectionprojection functionsfunctions to extract the first and second elements from a pair •Projection functionsProjection functions can be defined: •fun first(x,y) = x; •fun second( x, y)=y;
  • 9. 9 TYPES: VALUES AND OPERATIONS • Lists of Elements: •A list is a finite-length sequence of elements •Type A list consists of all lists of elements, where each element belongs to type A. •Example: •int list consists of all lists of integers •[1,2,3] is a list of three integers 1, 2, and 3. •[“red”, “white”, “blue”] is a list of three strings
  • 10. 10 TYPES: VALUES AND OPERATIONS •Operations on Lists •List-manipulation programs must be prepared to construct and inspect lists of any length. •Operations on list from ML: •null(x) True if x is the empty list, false otherwise. •hd(x) The first or head element of list x. •tl(x) The tail or rest of the list after the first element is removed. •a::x Construct a list with head a and tail x. Cons operator
  • 11. 11 TYPES: VALUES AND OPERATIONS •Types in ML Predeclared basic types of ML. Type Name Values Operations _____________________________________________________ boolean bool true,false =,<>,… integer int …,-1,0,1,2,… =,<>,<,+,*,div,mod,… real real …,0.0,…,3.14,.. =,<>,<,+,*,/,… string string “foo”,””quoted”” =,<>,… _____________________________________________________ •New basic types can be defined as needed by a datatype declaration •Example: datatype direction = ne | se |sw| nw;
  • 12. 12 FUNCTION DECLARATIONS • Functions as Algorithms A function declaration has three parts: •The name of the declared function •The parameters of the function •A rule for computing a result from the parameters
  • 13. 13 FUNCTION DECLARATIONS • Syntax of Function Declarations and Applications •The basic syntax for function declarations is fun <name><formal-parameter> = <body> •<name> is the function name •<formal-parameter> is a parameter name •<body> is an expression to be evaluated •fun successor n = n +1; •fun successor (n)= n +1; () are optional
  • 14. 14 FUNCTION DECLARATIONS • The use of a function within an expression is called an applicationapplication of the function. •Prefix notation is the rule for the application of declared function •<name><actual-parameter> •<name> is the function name •<actual-parameter> is an expression corresponding to the parameter name in the declaration of the function •Example: successor(2+3)
  • 15. 15 FUNCTION DECLARATIONS • Recursive Functions -- A function f is recursive if its body contains an application of f. •Example1: •Function len counts the number of elements in a list •fun len(x)= if null(x) then 0 else 1 + len(tl(x))
  • 16. 16 Approaches to Expression Evaluation •Innermost Evaluation •Outermost Evaluation •Selective Evaluation •Evaluation of Recursive Functions •Short-Circuit Evaluation
  • 17. 17 Type Checking Type Inference: •Wherever possible ,ML infers the type of an expression.An error is reported if the type of an expression cannot be inferred. •If E and F have type int then E+F also has type int . •In general, If f is a function of type A -->B , and a has type A, then f(a) has type B.
  • 18. 18 Type Names and Type Equivalence Two type expressions are said to be structurally equivalent if and only if they are equivalent under the following rules: 1. A type name is structurally equivalent to itself. 2. Two type expressions are structurally equivalent if they are formed by applying the same type constructor to structurally equivalent types. 3. After a type declaration, type n = T ,the type name n is structurally equivalent to T .
  • 19. 19 Overloading:Multiple Meanings A symbol is said to be overloaded if it has different meanings in different contexts.Family operator symbols like + and * are overloaded. e.g. 2+2 here + is of type int 2.5+3.6 here + is of type real. ML cannot resolve overloading in fun add(x,y) = x+y ; Explicit types can be used to resolve overloading. fun add(x,y): int =x+y ;
  • 20. PRESENTED BY SAJJAD ALI P M CS –B ,34 20