SlideShare a Scribd company logo
Functional Programming
Bas Bossink
April 2010
Contents
Introduction
Definition
History
Taxonomy
Features
Functional concepts
When to use it?
When not to use it?
Resources
Introduction
Disclaimer
Inventory
Anecdote
About
GFDL
on github
libre tools
Definition
Functions are central construct
Functions are regular values
passed around
returned
composed
(partially) applied
No variables but binding of values
all variables are immutable
Definition of a Function
Functions are mathematical
Example
Figure 1:
Non-example
Figure 2:
Definition of a Function
Same input -> same output
No side effects, pure
History
Lambda calculus
Alonzo Church 1930s
untyped lambda calculus
simply typed lambda calculus
Figure 3:
Taxonomy
Group functional languages across several axis:
Statically typed / Dynamically typed
Strong typing / Weak typing
Lazy / Eager
Single paradigm / Multi paradigm
Taxonomy
Taxonomy
Features
Read Eval Print Loop (REPL)
Type inference (var on steroids)
Pattern matching
Algabraic data types
Function composition
Anonymous functions (lambda expressions)
Closure
Features
Sequence Epressions (List Comprehensions)
Partial function application (currying)
Higher order functions (map, fold, filter)
Funtional concepts
Tail Recursion
Continuation passing style
Memoization
Computation Expressions (Monads)
Concept from mathematics, Category theory
A triple:
type constructor
bind aka chain operation
return aka inject operation
Category
a collection of elements
a collection of morphisms (think function)
a notion of composition of these morphisms
Example Grp, Set, Hask
Functor
Transformation between categories
Given category C, D, functor F
F : C -> D
f: A -> B then F(f) -> F(A) -> F(B)
Examples: F: Grp -> Set, forgetful functor
Monad
Functor: M: C -> C
unit: X -> M(X)
join: M(M(X)) -> M(X)
Monads
class Monad m where
(>>=) :: m a -> (a -> m b) -> m b
return :: a -> m a
instance Monad [] where
return x = [x]
xs >>= f = concat (map f xs)
When to use it?
stateless
data-transformations
calculation /scientific computing
parrallellism
When not to use it?
a lotta state
gui’s
Resources
F#
Expert F#
Wikibook
Developer Center
HubFs
Haskell
Real World Haskell (book)
Real World Haskell online
Haskell.org
Haskell lectures Erik Meijer
Yet another Haskell tutorial
Labs
Haskell
F#
fix code such that quickcheck/fscheck succeeds
solutions on solution branch
try euler project
Ad

More Related Content

What's hot (20)

Linked list
Linked listLinked list
Linked list
baabtra.com - No. 1 supplier of quality freshers
 
JDK8 Lambda expressions demo
JDK8 Lambda expressions demoJDK8 Lambda expressions demo
JDK8 Lambda expressions demo
MouryaKumar Reddy Rajala
 
Ch6
Ch6Ch6
Ch6
kinnarshah8888
 
Predictive parser
Predictive parserPredictive parser
Predictive parser
Jothi Lakshmi
 
Parsing
ParsingParsing
Parsing
ShrikantSharma86
 
Lecture11 syntax analysis_7
Lecture11 syntax analysis_7Lecture11 syntax analysis_7
Lecture11 syntax analysis_7
Mahesh Kumar Chelimilla
 
Swift
SwiftSwift
Swift
Futada Takashi
 
tutorials-c-sharp_understanding-generic-anonymous-methods-and-lambda-expressi...
tutorials-c-sharp_understanding-generic-anonymous-methods-and-lambda-expressi...tutorials-c-sharp_understanding-generic-anonymous-methods-and-lambda-expressi...
tutorials-c-sharp_understanding-generic-anonymous-methods-and-lambda-expressi...
Anil Sharma
 
LR(1) and SLR(1) parsing
LR(1) and SLR(1) parsingLR(1) and SLR(1) parsing
LR(1) and SLR(1) parsing
R Islam
 
Parsing (Automata)
Parsing (Automata)Parsing (Automata)
Parsing (Automata)
ROOP SAGAR
 
Lisp
LispLisp
Lisp
huzaifa ramzan
 
Lisp Programming Languge
Lisp Programming LangugeLisp Programming Languge
Lisp Programming Languge
Yaser Jaradeh
 
Lexical analysis
Lexical analysisLexical analysis
Lexical analysis
Richa Sharma
 
Type checking compiler construction Chapter #6
Type checking compiler construction Chapter #6Type checking compiler construction Chapter #6
Type checking compiler construction Chapter #6
Daniyal Mughal
 
Bottom up parser
Bottom up parserBottom up parser
Bottom up parser
Inocentshuja Ahmad
 
Top Down Parsing, Predictive Parsing
Top Down Parsing, Predictive ParsingTop Down Parsing, Predictive Parsing
Top Down Parsing, Predictive Parsing
Tanzeela_Hussain
 
Programming course slides c++ (Prof Mansoor Bhatti)
Programming course slides c++ (Prof Mansoor Bhatti)Programming course slides c++ (Prof Mansoor Bhatti)
Programming course slides c++ (Prof Mansoor Bhatti)
Syed Arslan Rizvi
 
Ll(1) Parser in Compilers
Ll(1) Parser in CompilersLl(1) Parser in Compilers
Ll(1) Parser in Compilers
Mahbubur Rahman
 
Implementation of lexical analyser
Implementation of lexical analyserImplementation of lexical analyser
Implementation of lexical analyser
Archana Gopinath
 
LL(1) parsing
LL(1) parsingLL(1) parsing
LL(1) parsing
KHYATI PATEL
 

Similar to Functional programming (20)

About Functional Programming
About Functional ProgrammingAbout Functional Programming
About Functional Programming
Aapo Kyrölä
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
Synesso
 
Functional programming seminar (haskell)
Functional programming seminar (haskell)Functional programming seminar (haskell)
Functional programming seminar (haskell)
Bikram Thapa
 
LISP: Introduction to lisp
LISP: Introduction to lispLISP: Introduction to lisp
LISP: Introduction to lisp
DataminingTools Inc
 
LISP: Introduction To Lisp
LISP: Introduction To LispLISP: Introduction To Lisp
LISP: Introduction To Lisp
LISP Content
 
Partial Functions In Scala
Partial Functions In ScalaPartial Functions In Scala
Partial Functions In Scala
Constantin Gonciulea
 
Lambda Expressions Java 8 Features usage
Lambda Expressions  Java 8 Features usageLambda Expressions  Java 8 Features usage
Lambda Expressions Java 8 Features usage
AsmaShaikh478737
 
Python Tutorial Part 1
Python Tutorial Part 1Python Tutorial Part 1
Python Tutorial Part 1
Haitham El-Ghareeb
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
home
 
The IoT Academy training part2 AI Architecture
The IoT Academy training part2 AI ArchitectureThe IoT Academy training part2 AI Architecture
The IoT Academy training part2 AI Architecture
The IOT Academy
 
whats new in java 8
whats new in java 8 whats new in java 8
whats new in java 8
Dori Waldman
 
Mit gnu scheme reference manual
Mit gnu scheme reference manualMit gnu scheme reference manual
Mit gnu scheme reference manual
Vitor Eduardo da Silva
 
Shapeless- Generic programming for Scala
Shapeless- Generic programming for ScalaShapeless- Generic programming for Scala
Shapeless- Generic programming for Scala
Knoldus Inc.
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009
Martin Odersky
 
Java 8
Java 8Java 8
Java 8
vilniusjug
 
F# Intro for Scala Developers
F# Intro for Scala DevelopersF# Intro for Scala Developers
F# Intro for Scala Developers
fsug
 
The Dictionary of Standard C 1st Edition Rex Jaeschke
The Dictionary of Standard C 1st Edition Rex JaeschkeThe Dictionary of Standard C 1st Edition Rex Jaeschke
The Dictionary of Standard C 1st Edition Rex Jaeschke
ilfatjasdip
 
PARADIGM IT.pptx
PARADIGM IT.pptxPARADIGM IT.pptx
PARADIGM IT.pptx
jamesmarken1
 
8. Functional Programming_updated(1).pptx
8. Functional Programming_updated(1).pptx8. Functional Programming_updated(1).pptx
8. Functional Programming_updated(1).pptx
jaymalachavan
 
F# 101
F# 101F# 101
F# 101
Chris Alcock
 
About Functional Programming
About Functional ProgrammingAbout Functional Programming
About Functional Programming
Aapo Kyrölä
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
Synesso
 
Functional programming seminar (haskell)
Functional programming seminar (haskell)Functional programming seminar (haskell)
Functional programming seminar (haskell)
Bikram Thapa
 
LISP: Introduction To Lisp
LISP: Introduction To LispLISP: Introduction To Lisp
LISP: Introduction To Lisp
LISP Content
 
Lambda Expressions Java 8 Features usage
Lambda Expressions  Java 8 Features usageLambda Expressions  Java 8 Features usage
Lambda Expressions Java 8 Features usage
AsmaShaikh478737
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
home
 
The IoT Academy training part2 AI Architecture
The IoT Academy training part2 AI ArchitectureThe IoT Academy training part2 AI Architecture
The IoT Academy training part2 AI Architecture
The IOT Academy
 
whats new in java 8
whats new in java 8 whats new in java 8
whats new in java 8
Dori Waldman
 
Shapeless- Generic programming for Scala
Shapeless- Generic programming for ScalaShapeless- Generic programming for Scala
Shapeless- Generic programming for Scala
Knoldus Inc.
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009
Martin Odersky
 
F# Intro for Scala Developers
F# Intro for Scala DevelopersF# Intro for Scala Developers
F# Intro for Scala Developers
fsug
 
The Dictionary of Standard C 1st Edition Rex Jaeschke
The Dictionary of Standard C 1st Edition Rex JaeschkeThe Dictionary of Standard C 1st Edition Rex Jaeschke
The Dictionary of Standard C 1st Edition Rex Jaeschke
ilfatjasdip
 
8. Functional Programming_updated(1).pptx
8. Functional Programming_updated(1).pptx8. Functional Programming_updated(1).pptx
8. Functional Programming_updated(1).pptx
jaymalachavan
 
Ad

Functional programming

  翻译: