Download Functional Paradigm

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Join-pattern wikipedia , lookup

Scala (programming language) wikipedia , lookup

Go (programming language) wikipedia , lookup

Logic programming wikipedia , lookup

Recursion (computer science) wikipedia , lookup

Control flow wikipedia , lookup

Abstraction (computer science) wikipedia , lookup

Stream processing wikipedia , lookup

Programming language wikipedia , lookup

Common Lisp wikipedia , lookup

Lisp (programming language) wikipedia , lookup

C Sharp (programming language) wikipedia , lookup

Object-oriented programming wikipedia , lookup

Structured programming wikipedia , lookup

Corecursion wikipedia , lookup

Reactive programming wikipedia , lookup

Falcon (programming language) wikipedia , lookup

Functional programming wikipedia , lookup

Transcript
The Functional Paradigm
Joseph Spring
7COM1023 Programming Paradigms
1
Discussion
•
•
•
•
•
Introduction
Functions and the λ Calculus
Lisp
Haskell
Summary
2
The Functional Paradigm
• Emerged as a distinct paradigm during the 1960’s
• Motivated by :
– researchers in (AI) Artificial Intelligence and related subfields
• Symbolic computation
• Theorem proving
• Rule based systems
• Natural language processing
• The needs of the above were not well met by
imperative paradigm languages during the 60’s
3
The Functional Paradigm
• First functional language was Lisp
– Developed by John McCarthy in 1960
– Described in Lisp 1.5 Programmers Manual in 1965
• Notable for clarity and brevity (just 116 pages)
• ‘The Lisp language is primarily for symbolic data
processing.
– It has been used for symbolic calculations in:
•
•
•
•
Differential and integral calculus
Electrical circuit design
Mathematical logic
Game playing and other fields in AI
4
The Functional Paradigm
• In Functional Programming
– Computations are viewed as mathematical
functions mapping inputs to outputs
– In imperative programming we work with the
notion of state
• need to work with assignment statements
– In Functional programming
• we do not work with the notion of a state
– Hence no need for assignment statements
• Implication for control structures?
– Loops? No way to increment or decrement variables i in a state
– Use recursion
5
The Functional Paradigm
• In practice most Functional Programming languages
– Support the notions of variable, assignment and
looping
– Such languages are referred to as ‘impure’
functional programming languages
• Point:
– The notions of variable, assignment and (non
recursive) looping are NOT part of the ‘pure’
functional programming model
• Functional paradigm seen by some as a more reliable
paradigm for software design than the imperative
paradigm
6
The Functional Paradigm
• For a comparison of the imperative and functional
paradigms see for example
– John Hughes ‘Why Functional Programming
Matters’, The Computer Journal, 32, 2, (1989) pp 98
– 107
Exercise
Compare and contrast the Imperative Paradigm
with the Functional Paradigm
7
Lisp
We have seen examples of syntax and semantics used
in Lisp through DrRacket and Racket. In particular:
• Documentation Window
• Debug Window
8
Lisp
We have:
• Input and Evaluated
– Data
– Expressions
– Constants
• Explored a range of Lisp functions
• Defined and Evaluated
–
–
–
–
–
Constants
Expressions
Functions
Functional Composition
Conditionals
• And are currently exploring
– Recursion
9
Functional Paradigm
We now formally review:
– Sets and Relations
– Source, Domain, Target, Range and Codomain
– Types of Relation
– Relations and Functions
– Functional Composition
10
Haskell
We will discuss Haskell
11
References
1)
2)
3)
McCarthy, John et al, ‘Lisp 1.5 Programmers
Manual’ MIT Press, 1965
John Hughes ‘Why Functional Programming
Matters’, The Computer Journal, 32, 2, (1989)
pp 98 – 107
Church, Alonzo ‘The Calculi of Lambda
Conversion’, Princeton University Press, (1941)
12