Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.

Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.

Like this presentation? Why not share!

- Mantendo seu ambiente de CI na nuvem by Adriano Bonat 185 views
- Programando arduino com javascript by Desiree Santos 355 views
- Funcionamento e otimização da Gar... by Adriano Bonat 769 views
- Functional Programming and Haskell ... by Adriano Bonat 694 views
- How to Fix the Internet by LinkedIn Editors'... 44153 views
- 32 Ways a Digital Marketing Consult... by Barry Feldman 140691 views

2,757 views

Published on

No Downloads

Total views

2,757

On SlideShare

0

From Embeds

0

Number of Embeds

30

Shares

0

Downloads

47

Comments

0

Likes

5

No embeds

No notes for slide

- 1. Functional Programming #FTW Adriano Bonat adrianob@gmail.com @tanob
- 2. Why FP is a hot topic? • Multicore CPUs • VM based languages • Great and easy to write DSLs • Parsers • Hardware design • Expressiveness
- 3. What is it? • Different programming paradigm • OO • Logic • Procedural • Functions are the main element in the language
- 4. Function applications “Functional programming is so called because a program consists entirely of functions. [...] Typically the main function is deﬁned in terms of other functions, which in turn are deﬁned in terms of still more functions, until at the bottom level the functions are language primitives.” John Hughes, 1989 - Why functional programming matters
- 5. Origin Alonzo Church developed Lambda Calculus as part of his investigations on Math foundations on 1936.
- 6. Lambda Calculus • Variables • Expressions (e e ) 1 2 • Lambda abstractions (λx. e)
- 7. Lambda Calculus (I) • true = λxy. x • false = λxy. y • NOT a = (a)(false)(true) • a AND b = (a)(b)(false) • a OR b = (a)(true)(b) • a XOR b = (a)((b)(false)(true))(b)
- 8. Basic concepts • Pureness • Pattern Matching • Lazyness • High Order Functions • Curriﬁcation (aka Partial Application)
- 9. Pureness • No side-effects • A function call can have no effect other than to compute its result • Expressions can be evaluated at any time • Programs are “referentially transparent”
- 10. Imperative style function sum(elems: list of int) returns int { int total = 0; for elem in elems { total = total + elem; } return total; }
- 11. Imperative style function sum(elems: list of int) returns int { int total = 0; for elem in elems { total = total + elem; } return total; } Computation method is variable assignment
- 12. Functional style Pattern matching is cool! Deﬁnition: sum [] = 0 sum elem:rest = elem + sum rest Application: sum [1,2,3,10]
- 13. Functional style Deﬁnition: sum [] = 0 sum elem:rest = elem + sum rest Application: sum [1,2,3,10] Computation method is function application
- 14. Lazyness • aka “call by need” • Expressions can be evaluated when necessary • Allows the use of inﬁnite lists
- 15. Lazyness (I) Deﬁnition: even_numbers :: [Int] even_numbers = filter even [1..] Application: take 5 even_numbers
- 16. Lazyness (II) fibs :: [Int] fibs = 0 : 1 : zipWith (+) fibs (tail fibs) From: http://en.wikipedia.org/wiki/Lazy_evaluation
- 17. High Order Functions Functions which at least: • Receive functions as parameters • Return functions (aka curried functions)
- 18. High Order Functions (I) map :: (a -> b) -> [a] -> [b] map f [] = [] map f (x:xs) = f x : map f xs
- 19. Curriﬁcation sum :: Int -> Int -> Int sum x y = x + y inc :: Int -> Int inc = sum 1
- 20. Where to go now? Suggestions: • Haskell • LISP • Scheme • Common LISP (CL) • Clojure • Erlang • Scala • F#
- 21. Haskell • Pure n’ lazy • Static typed • Type classes • Monads • Lots of research & dev.
- 22. Haskell (I) Freely available online: http://book.realworldhaskell.org/
- 23. LISP • First functional language • Lots of ﬂavors • Deal with parenthesis! • Dynamic typed • Homoiconic
- 24. Scheme Freely available online: http://mitpress.mit.edu/sicp/
- 25. Clojure • Runs on JVM • Concurrency
- 26. Erlang • Fault tolerant systems • Concurrency • Super easy! • Dynamic typed
- 27. Scala • Runs on JVM • Several nice features • Looks complex • Static typed
- 28. F# • Runs on .NET • Result of MS’s investment on FP • Simon Peyton Jones (Haskell contrib) • Don Syme (F# creator) • Erik Meijer (FP advocator, LINQ creator)
- 29. F# (I) Pragmatic F# In Action Josh Graham and Amanda Laucher http://www.infoq.com/presentations/Pragmatic-F-Sharp-in-Action
- 30. Your Knowledge Portfolio "Learn at least one new language every year. [...] Different languages solve the same problems in different ways. By learning several different approaches, you can help broaden your thinking and avoid getting stuck in a rut." The Pragmatic Programmer
- 31. Functional Programming #FTW Adriano Bonat adrianob@gmail.com @tanob

No public clipboards found for this slide

×
### Save the most important slides with Clipping

Clipping is a handy way to collect and organize the most important slides from a presentation. You can keep your great finds in clipboards organized around topics.

Be the first to comment