• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Diving into Functional Programming
 

Diving into Functional Programming

on

  • 3,486 views

 

Statistics

Views

Total Views
3,486
Views on SlideShare
3,200
Embed Views
286

Actions

Likes
9
Downloads
58
Comments
0

8 Embeds 286

https://twitter.com 170
http://www.scoop.it 73
http://www.linkedin.com 35
http://twitter.com 4
https://api.twitter.com 1
https://twimg0-a.akamaihd.net 1
http://eventifier.co 1
https://www.linkedin.com 1
More...

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

    Diving into Functional Programming Diving into Functional Programming Presentation Transcript

    • Learning FP Lev Walkin @levwalkin
    • MyselfFounder, Chief Editor of a peer-reviewed«Practice of Functional Programming»journal http://fprog.ru/CTO Echo, a venture backed companyhttp://aboutecho.com/Proficient in N languages, M of them FP
    • Echo50,000+ HTTP requests per second500,000+ simultaneous users on site1,527,721,774 search queries last monthJavaScript, Clojure, Haskell, C, LAMP, RoR,OCaml, Python, Perl, Visual Basic, C++
    • What’s your reason to learn FP?1. You already suspect that FP approach works best for your domain2. You want to learn FP to expand your tool set
    • Mature optionsHaskell (OCaml, F#)ScalaClojure (CL, Scheme)Erlang
    • Statically typedHaskell, OCaml, F# — part of ML familyUtilize Hindley—Milner type inferenceYou might not even SEE any typesTypes provide useful documentation
    • Statically typedScalaVery sophisticated type systemType inference fails often (you have toannotate with types)Lots of syntax sugar, lots of ways to dothings
    • Type inference-- Haskell programmain = print “Hello, world!”(* OCaml program *)let main = print_string “Hello, world!”
    • Explicit types-- Haskell programmain :: IO ()main = print “Hello, world!”(* OCaml program *)val main : unitlet main = print_string “Hello, world!”
    • Dynamically typedLISP (type annotations are NOT statictypes)Erlang (Dialyzer helps a bit)
    • Pure FP training...requires pure language.Haskell is the only viable option.
    • Purity in HaskellFunction have no side effectsAll state changes are only throughspecially constructed monads (IO, ST)Static types force isolationLazyness thrown in for a deeper fun
    • HaskellMedium-size syntax, relatively easy tolearn, but...Simple & interesting things are EASYYet, there are LOTS of abstractions andapproaches to learn: Type classes,Monads, Arrows, parsing, pretty-printing.This is why we chose Haskell, right?
    • “One” “silly” “example.”
    • Haskell, OCaml, F#data Tree a =! Leaf a! | Node (Tree a) (Tree a)type ‘a tree =! | Leaf of ‘a! | Node of ‘a tree * ‘a treetype Tree<a> = | Leaf of ‘a | Branch of ‘a Tree * ‘a Tree http://fprog.ru/2009/issue2/roman-dushkin-algebraic-data-types/
    • “One” 3 “silly” “example.” 5 8
    • Haskelldata Tree String =! Leaf String! | Node (Tree String) (Tree String)strToLenTree :: Tree String ! Tree IntstrToLenTree (Leaf s) = Leaf (length s)strToLenTree (Node left right) =! ! ! Node (strToLenTree left)! ! ! ! ! (strToLenTree right)
    • Haskelldata Tree a =! Leaf a! | Node (Tree a) (Tree a)mapTree :: (a ! b) ! Tree a ! Tree bmapTree f (Leaf x) = Leaf (f x)mapTree f (Node left right) =! ! ! ! Node (mapTree f left)! ! ! ! ! ! (mapTree f right)strToLenTree :: Tree String ! Tree IntstrToLenTree = mapTree length
    • Prototyping[~]> ghci tree.hsGHCi, version 7.0.4 :? for help[1 of 1] Compiling Main ( tree.hs, interpreted )Ok, modules loaded: Main.*Main> let tree = Node (Leaf "An") (Leaf "example")*Main> mapTree (s -> length s) treeNode (Leaf 2) (Leaf 7)*Main> mapTree (s -> filter Data.Char.isUpper s) treeNode (Leaf "A") (Leaf "")*Main> mapTree (filter Data.Char.isLower) treeNode (Leaf "n") (Leaf "example")*Main> :t mapTreemapTree :: (a -> b) -> Tree a -> Tree b*Main> :t mapTree lengthmapTree length :: Tree [a] -> Tree Int
    • LISPClojure: immutability, persistent datastructures, JVMScheme: very small language, suitable forteaching/learningCommon Lisp: it is a fat multiparadigmlanguage and has everything (thoughparts may be rotten a bit)
    • ErlangSimple languageTelecom systems, 24/7, системымассового обслуживания (web?)Hot code reload, deep introspection,embedded facilities for easier clustering
    • Erlang% Reverse a stringreverse(String) -> reverse2(String, []).% Reverse with an accumulatorreverse2([ ], Acc) -> Acc;reverse2([Head | Tail], Acc) ->! reverse2(Tail, [Head | Acc]).
    • Erlang% Sends request to the [remote] system% and waits for the response backsend_and_wait(Pid, Message, Timeout) ->! Pid ! Message,! receive! ! Response -> {ok, Response}! after! ! Timeout -> {error, timeout}! end.
    • Clojure vs LISP*NEW language, with sound idiomsImmutable data structures are idiomaticFast pace of developmentJVM may be a big bon for someLearn it if you want sound, practicallanguage http://tonsky.livejournal.com/tag/clojure
    • Scheme vs LISP*Small, simple language (R5RS)A basis for SICP — Structure andInterpretation of Computer ProgramsLearn SICP if you want to studyProgramming
    • CL vs LISP*Many complex ideas mixed inNo enforcement of a good style — youhave to do it on your ownLearn it if you want unrestricted power
    • Haskell vs ML*More sound type systemLOTS of language research happen onHaskellLearn it if you want to learn FPLearn it if it fits your domain well http://www.ozon.ru/context/detail/id/8696277/
    • OCamlSeveral mostly compatible syntaxesYou can always create a mutable variableor class field, though not idiomaticClearer semantics and computationmodel (straightforward translation toassembly) http://mirror.ocamlcore.org/ocaml-tutorial.org/the_basics.html
    • OCaml vs ML*OCaml is to Haskell as C is to C++Poor library supportFAST (on 1-core systems)Learn it if you want a practical tool andnot satisfied with Haskell or F# http://www.slideshare.net/michielovereem/beyond-functional- programming-in-haskell-an-introduction-to-ocaml
    • F# vs ML*Works under Microsoft .NetF# on Mono is somewhat usableLearn it if you want to tinker with FP onMS platform http://www.ozon.ru/context/detail/id/6151130/
    • Erlang vs *SMALL language, somewhat bigger OTPGreat support for concurrency (Actors),and parallelismHot code reload & run time introspectionOOP on the outside; FP on the insideLearn it if you build 24/7 productionsystem
    • Scala vs *Big language, a functional C++ of sortsJVMLearn it if you want a great tool, notsatisfied with Java, yet have noappreciation for true elegance (Clojure)
    • Learning FPHaskell provides models and abstractions(read papers) — pure FPScheme teaches you Programming (readSICP)Everything else is too practical
    • Practicing FP.Net → F#JVM → Clojure (elegance and simplicity),Scala (less restrictions)!{.Net|JVM} → OCaml (if you do not needlibraries), Clojure, Haskell (if you haveballs)24/7 → Erlang
    • For individualsYou want flexible system which allowsyou to cut cornersCommon LispScalaF#
    • For teamsYou want to think about lifecycle,support, maintenance, group dynamicsOCaml (static typing provides someguarantees)Erlang (simple and straightforward,designed to withstand errors, good fornovices)
    • For teamsScala gets increasingly popular becausepeople do not appreciate elegance andsound restrictionsPeople will throw up in a few yearsworking with accumulated Scala code...like C++ http://ru.xored.com/2012/12/02/scala/
    • Haskell resourcesМягкое введение в HaskellИзучай Haskell во имя добра! http://www.rsdn.ru/article/haskell/haskell_part1.xml
    • Clojure resources1. Learn spoken English2. Журнал Никиты Прокопова (tonsky@LJ) содержит ссылки и рекомендации http://tonsky.livejournal.com/tag/clojure
    • Erlang resources1. Programming Erlang: Software for a Concurrent World2. http://learnyousomeerlang.com http://www.ozon.ru/context/detail/id/3645143/
    • Shameless plugЖурнал «Практикафункциональногопрограммирования»fprog.ru@fprogru
    • Thank you!Questions?jobs@aboutecho.com (мы пишем на Руби!)