• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Functional Programming #FTW
 

Functional Programming #FTW

on

  • 3,243 views

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.

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.

Statistics

Views

Total Views
3,243
Views on SlideShare
3,224
Embed Views
19

Actions

Likes
5
Downloads
41
Comments
0

2 Embeds 19

http://www.slideshare.net 13
http://www.linkedin.com 6

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Functional Programming #FTW Functional Programming #FTW Presentation Transcript

    • Functional Programming #FTW Adriano Bonat adrianob@gmail.com @tanob
    • Why FP is a hot topic? • Multicore CPUs • VM based languages • Great and easy to write DSLs • Parsers • Hardware design • Expressiveness
    • What is it? • Different programming paradigm • OO • Logic • Procedural • Functions are the main element in the language
    • 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
    • Origin Alonzo Church developed Lambda Calculus as part of his investigations on Math foundations on 1936.
    • Lambda Calculus • Variables • Expressions (e e ) 1 2 • Lambda abstractions (λx. e)
    • 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)
    • Basic concepts • Pureness • Pattern Matching • Lazyness • High Order Functions • Currification (aka Partial Application)
    • 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”
    • Imperative style function sum(elems: list of int) returns int { int total = 0; for elem in elems { total = total + elem; } return total; }
    • 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
    • Functional style Pattern matching is cool! Definition: sum [] = 0 sum elem:rest = elem + sum rest Application: sum [1,2,3,10]
    • Functional style Definition: sum [] = 0 sum elem:rest = elem + sum rest Application: sum [1,2,3,10] Computation method is function application
    • Lazyness • aka “call by need” • Expressions can be evaluated when necessary • Allows the use of infinite lists
    • Lazyness (I) Definition: even_numbers :: [Int] even_numbers = filter even [1..] Application: take 5 even_numbers
    • Lazyness (II) fibs :: [Int] fibs = 0 : 1 : zipWith (+) fibs (tail fibs) From: http://en.wikipedia.org/wiki/Lazy_evaluation
    • High Order Functions Functions which at least: • Receive functions as parameters • Return functions (aka curried functions)
    • High Order Functions (I) map :: (a -> b) -> [a] -> [b] map f [] = [] map f (x:xs) = f x : map f xs
    • Currification sum :: Int -> Int -> Int sum x y = x + y inc :: Int -> Int inc = sum 1
    • Where to go now? Suggestions: • Haskell • LISP • Scheme • Common LISP (CL) • Clojure • Erlang • Scala • F#
    • Haskell • Pure n’ lazy • Static typed • Type classes • Monads • Lots of research & dev.
    • Haskell (I) Freely available online: http://book.realworldhaskell.org/
    • LISP • First functional language • Lots of flavors • Deal with parenthesis! • Dynamic typed • Homoiconic
    • Scheme Freely available online: http://mitpress.mit.edu/sicp/
    • Clojure • Runs on JVM • Concurrency
    • Erlang • Fault tolerant systems • Concurrency • Super easy! • Dynamic typed
    • Scala • Runs on JVM • Several nice features • Looks complex • Static typed
    • 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)
    • F# (I) Pragmatic F# In Action Josh Graham and Amanda Laucher http://www.infoq.com/presentations/Pragmatic-F-Sharp-in-Action
    • 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
    • Functional Programming #FTW Adriano Bonat adrianob@gmail.com @tanob