Download presentation
Presentation is loading. Please wait.
Published byTimothy Watkins Modified over 9 years ago
1
Functional Programming a (very) short introduction Ben Couste 06/10/2010
2
Functional Programming “ML, Lisp, and Haskell are the only programming languages that I've seen where one spends more time thinking than typing.” - Philip Greenspun
3
Outline What is Functional Programming (FP)? Why would I want to use it? Examples!
4
What is FP? Different paradigm Imperative programming (think C or Java) is about changes in the state of data Functional programming is about the application of functions Writing “pure” code
5
Barrier to entry Different programming paradigm “A monad is just a monoid in the category of endofunctors!” Mathematicians love FP Large and intimidating community (#haskell on irc.freenode.org) Generally very business-unfriendly
6
Purity Pure code has no side effects Easier to debug! Not always possible (I/O, mutable arrays)
7
Typing Write well-typed programs Program will not compile otherwise!
8
Recursion example Classic method in CS Heavily used in FP Each new term in the Fibonacci sequence is generated by adding the previous two terms. Find the sum of all the even-valued terms in the sequence which do not exceed four million. (project-euler.net)
9
Haskell Implementation Prelude> let fibs = 0 : 1 : zipWith (+) fibs (tail fibs) Prelude> sum [x | x <- (takeWhile (< 4000000) fibs), even x] 4613732
10
Shifting functions around Functions can be passed as parameters! Code reuse anyone? Syntactic sugar Fun!
11
Further reading http://learnyouahaskell.com http://lambda-the-ultimate.org/ My handouts on the course website
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.