SlideShare una empresa de Scribd logo
1 de 21
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

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Basic data types in python
Basic data types in pythonBasic data types in python
Basic data types in python
 
Values and Data types in python
Values and Data types in pythonValues and Data types in python
Values and Data types in python
 
Getting started with c++
Getting started with c++Getting started with c++
Getting started with c++
 
Programming construction tools
Programming construction toolsProgramming construction tools
Programming construction tools
 
Frequently asked questions in c
Frequently asked questions in cFrequently asked questions in c
Frequently asked questions in c
 
Chapter 2.datatypes and operators
Chapter 2.datatypes and operatorsChapter 2.datatypes and operators
Chapter 2.datatypes and operators
 
LISP: Input And Output
LISP: Input And OutputLISP: Input And Output
LISP: Input And Output
 
Lec4slides
Lec4slidesLec4slides
Lec4slides
 
Frequently asked questions in c
Frequently asked questions in cFrequently asked questions in c
Frequently asked questions in c
 
Input processing and output in Python
Input processing and output in PythonInput processing and output in Python
Input processing and output in Python
 
Python revision tour II
Python revision tour IIPython revision tour II
Python revision tour II
 
Basic of c &c++
Basic of c &c++Basic of c &c++
Basic of c &c++
 
C++
C++C++
C++
 
Token and operators
Token and operatorsToken and operators
Token and operators
 
Python second ppt
Python second pptPython second ppt
Python second ppt
 
Lec9
Lec9Lec9
Lec9
 
Learn C LANGUAGE at ASIT
Learn C LANGUAGE at ASITLearn C LANGUAGE at ASIT
Learn C LANGUAGE at ASIT
 
M C6java2
M C6java2M C6java2
M C6java2
 
Ch5a
Ch5aCh5a
Ch5a
 
Data types and Operators
Data types and OperatorsData types and Operators
Data types and Operators
 

Destacado

Object oriented-programming-vs-procedural-programming
Object oriented-programming-vs-procedural-programmingObject oriented-programming-vs-procedural-programming
Object oriented-programming-vs-procedural-programmingkukurmutta
 
Procedural vs. object oriented programming
Procedural vs. object oriented programmingProcedural vs. object oriented programming
Procedural vs. object oriented programmingHaris 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 mindSander Mak (@Sander_Mak)
 
Functional Programming Fundamentals
Functional Programming FundamentalsFunctional Programming Fundamentals
Functional Programming FundamentalsShahriar 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 Conceptsthinkphp
 

Destacado (13)

Object oriented-programming-vs-procedural-programming
Object oriented-programming-vs-procedural-programmingObject oriented-programming-vs-procedural-programming
Object oriented-programming-vs-procedural-programming
 
Procedural vs. object oriented programming
Procedural vs. object oriented programmingProcedural vs. object oriented programming
Procedural vs. object oriented programming
 
Ppl pdf
Ppl pdfPpl pdf
Ppl pdf
 
Ak procedural vs oop
Ak procedural vs oopAk procedural vs oop
Ak procedural vs oop
 
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...
 
Prgramming paradigms
Prgramming paradigmsPrgramming paradigms
Prgramming paradigms
 
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
 
operating system structure
operating system structureoperating system structure
operating system structure
 
Functional Programming Fundamentals
Functional Programming FundamentalsFunctional Programming Fundamentals
Functional Programming Fundamentals
 
Introduction to Procedural Programming in C++
Introduction to Procedural Programming in C++Introduction to Procedural Programming in C++
Introduction to Procedural Programming in C++
 
Oops ppt
Oops pptOops ppt
Oops ppt
 
Functional Programming Patterns (BuildStuff '14)
Functional Programming Patterns (BuildStuff '14)Functional Programming Patterns (BuildStuff '14)
Functional Programming Patterns (BuildStuff '14)
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts
 

Similar a Elements of functional programming

MODULE-2.pptx
MODULE-2.pptxMODULE-2.pptx
MODULE-2.pptxASRPANDEY
 
Acm aleppo cpc training sixth session
Acm aleppo cpc training sixth sessionAcm aleppo cpc training sixth session
Acm aleppo cpc training sixth sessionAhmad Bashar Eter
 
An Introduction : Python
An Introduction : PythonAn Introduction : Python
An Introduction : PythonRaghu Kumar
 
12TypeSystem.pdf
12TypeSystem.pdf12TypeSystem.pdf
12TypeSystem.pdfMdAshik35
 
Programming with Python - Week 3
Programming with Python - Week 3Programming with Python - Week 3
Programming with Python - Week 3Ahmet 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 AlgorithmsBlue Elephant Consulting
 
Python programming
Python programmingPython programming
Python programmingsirikeshava
 
Demystifying Shapeless
Demystifying Shapeless Demystifying Shapeless
Demystifying Shapeless Jared Roesch
 
Presentation on python data type
Presentation on python data typePresentation on python data type
Presentation on python data typeswati 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 Pythonyashar Aliabasi
 
c programming 2nd chapter pdf.PPT
c programming 2nd chapter pdf.PPTc programming 2nd chapter pdf.PPT
c programming 2nd chapter pdf.PPTKauserJahan6
 
Introduction to Problem Solving C Programming
Introduction to Problem Solving C ProgrammingIntroduction to Problem Solving C Programming
Introduction to Problem Solving C ProgrammingRKarthickCSEKIOT
 
chapter-3-engdata-handling1_1585929972520 by EasePDF.pptx
chapter-3-engdata-handling1_1585929972520 by EasePDF.pptxchapter-3-engdata-handling1_1585929972520 by EasePDF.pptx
chapter-3-engdata-handling1_1585929972520 by EasePDF.pptxJahnavi113937
 
python-presentation.pptx
python-presentation.pptxpython-presentation.pptx
python-presentation.pptxVijay Krishna
 
Functions, List and String methods
Functions, List and String methodsFunctions, List and String methods
Functions, List and String methodsPranavSB
 

Similar a Elements of functional programming (20)

MODULE-2.pptx
MODULE-2.pptxMODULE-2.pptx
MODULE-2.pptx
 
Acm aleppo cpc training sixth session
Acm aleppo cpc training sixth sessionAcm aleppo cpc training sixth session
Acm aleppo cpc training sixth session
 
An Introduction : Python
An Introduction : PythonAn Introduction : Python
An Introduction : Python
 
12TypeSystem.pdf
12TypeSystem.pdf12TypeSystem.pdf
12TypeSystem.pdf
 
unit1 python.pptx
unit1 python.pptxunit1 python.pptx
unit1 python.pptx
 
Programming with Python - Week 3
Programming with Python - Week 3Programming with Python - Week 3
Programming with Python - Week 3
 
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
 
Python programming
Python programmingPython programming
Python programming
 
Demystifying Shapeless
Demystifying Shapeless Demystifying Shapeless
Demystifying Shapeless
 
Python Data-Types
Python Data-TypesPython Data-Types
Python Data-Types
 
Presentation on python data type
Presentation on python data typePresentation on python data type
Presentation on python data type
 
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
 
Chapter02.PPT
Chapter02.PPTChapter02.PPT
Chapter02.PPT
 
c programming 2nd chapter pdf.PPT
c programming 2nd chapter pdf.PPTc programming 2nd chapter pdf.PPT
c programming 2nd chapter pdf.PPT
 
Introduction to Problem Solving C Programming
Introduction to Problem Solving C ProgrammingIntroduction to Problem Solving C Programming
Introduction to Problem Solving C Programming
 
Concepts
ConceptsConcepts
Concepts
 
chapter-3-engdata-handling1_1585929972520 by EasePDF.pptx
chapter-3-engdata-handling1_1585929972520 by EasePDF.pptxchapter-3-engdata-handling1_1585929972520 by EasePDF.pptx
chapter-3-engdata-handling1_1585929972520 by EasePDF.pptx
 
python-presentation.pptx
python-presentation.pptxpython-presentation.pptx
python-presentation.pptx
 
Functions, List and String methods
Functions, List and String methodsFunctions, List and String methods
Functions, List and String methods
 
Python Basics
Python BasicsPython Basics
Python Basics
 

Último

Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfROCENODodongVILLACER
 
Earthing details of Electrical Substation
Earthing details of Electrical SubstationEarthing details of Electrical Substation
Earthing details of Electrical Substationstephanwindworld
 
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgUnit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgsaravananr517913
 
8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitter8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitterShivangiSharma879191
 
Piping Basic stress analysis by engineering
Piping Basic stress analysis by engineeringPiping Basic stress analysis by engineering
Piping Basic stress analysis by engineeringJuanCarlosMorales19600
 
Class 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm SystemClass 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm Systemirfanmechengr
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptSAURABHKUMAR892774
 
lifi-technology with integration of IOT.pptx
lifi-technology with integration of IOT.pptxlifi-technology with integration of IOT.pptx
lifi-technology with integration of IOT.pptxsomshekarkn64
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...Chandu841456
 
Transport layer issues and challenges - Guide
Transport layer issues and challenges - GuideTransport layer issues and challenges - Guide
Transport layer issues and challenges - GuideGOPINATHS437943
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEroselinkalist12
 
welding defects observed during the welding
welding defects observed during the weldingwelding defects observed during the welding
welding defects observed during the weldingMuhammadUzairLiaqat
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)Dr SOUNDIRARAJ N
 
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncWhy does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncssuser2ae721
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 

Último (20)

Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdf
 
Earthing details of Electrical Substation
Earthing details of Electrical SubstationEarthing details of Electrical Substation
Earthing details of Electrical Substation
 
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgUnit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
 
8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitter8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitter
 
Piping Basic stress analysis by engineering
Piping Basic stress analysis by engineeringPiping Basic stress analysis by engineering
Piping Basic stress analysis by engineering
 
Class 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm SystemClass 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm System
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.ppt
 
lifi-technology with integration of IOT.pptx
lifi-technology with integration of IOT.pptxlifi-technology with integration of IOT.pptx
lifi-technology with integration of IOT.pptx
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...
 
Transport layer issues and challenges - Guide
Transport layer issues and challenges - GuideTransport layer issues and challenges - Guide
Transport layer issues and challenges - Guide
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
 
welding defects observed during the welding
welding defects observed during the weldingwelding defects observed during the welding
welding defects observed during the welding
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
 
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncWhy does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 

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