An introduction to the basic concepts on functional programming, explaining why it is a hot topic for some years now, what it is and some suggestions of functional languages to be learned.
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 defined in terms of other
functions, which in turn are defined in terms of still
more functions, until at the bottom level the functions
are language primitives.”
John Hughes, 1989 - Why functional programming matters
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
• Currification (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”
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
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