SlideShare une entreprise Scribd logo
1  sur  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

Contenu connexe

Tendances

Tendances (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
 

En vedette

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
 

En vedette (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
 

Similaire à 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
 
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
 
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
 

Similaire à 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
 
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...
 
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
 

Dernier

Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur EscortsRussian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesPrabhanshu Chaturvedi
 
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGMANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGSIVASHANKAR N
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdfKamal Acharya
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingrknatarajan
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 

Dernier (20)

Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur EscortsRussian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
 
Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and Properties
 
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGMANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 

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