Your SlideShare is downloading.
×

×
# Saving this for later?

### Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

#### Text the download link to your phone

Standard text messaging rates apply

Like this presentation? Why not share!

- F# Tutorial @ QCon by Tomas Petricek 3257 views
- Introduction to F# by Jonas Follesø 935 views
- F# Presentation by mrkurt 1690 views
- Thinking in F# by Michael Clement 249 views
- F# Type Provider for R Statistical ... by Howard Mansell 4743 views
- F sharp by Trần Quang 31 views
- London F-Sharp User Group : Don Sym... by Skills Matter 1548 views
- An Introduction to FSharp by Horacio Nuñez 532 views
- 20 Years of Applied Ontology by Nicola Guarino 141 views
- EKAW2014 Keynote: Ontology Engineer... by Oscar Corcho 1696 views
- Introduction to FSharp by Valdis Iljuconoks 266 views
- F# Eye for the C# guy - Øredev 2013 by Phillip Trelford 3632 views

Like this? Share it with your network
Share

888

views

views

Published on

A presentation about functional programming in general and F# in particular.

A presentation about functional programming in general and F# in particular.

No Downloads

Total Views

888

On Slideshare

0

From Embeds

0

Number of Embeds

1

Shares

0

Downloads

27

Comments

0

Likes

2

No embeds

No notes for slide

- 1. Functional programming in F# The Why, What and How
- 2. Back in the days... ISWIM λ 1958 LISP 1966 1930-ish 1962 APL 1973 ML 2007 1977 FP Clojure2005 F# 1986 Erlang 2003 Scala 1988 Haskell Ocaml 1996
- 3. Some definitionsProgram Data - Logic - ControlDeclarative Logic - Referential transparencyImperative Logic - Control - Side effects
- 4. Functional programming language DeclarativeFirst class λHigher-Order ImmutabilityFunctions
- 5. The PAIN of imperativenessScrewupability Shared mutable states
- 6. Why not functional programming? • Too low dev replacability • Legacy code not functional • Bad interop, few libs • Devs find it too hard • Customers don’t care anyway
- 7. Why Functional Programming?let sum lst = foldr (+) lst 0let product lst = foldr (*) lst 1let append l1 l2 = foldr cons l1 l2let length lst = foldr (+) lst 0let map f lst = foldr (cons << f) lst []
- 8. FP demand UK ClojureScalaF# Erlang
- 9. Real-world usesF# Svea Ekonomi, Microsoft (Halo), Credit Suisse, ProverHaskell AT & T, ScriveErlang Ericsson, Klarna, Basho, FacebookLisp Yahoo StoreScala Twitter, LinkedIn
- 10. Why F#?Functional + OO + .NET + Open Source => The Most Powerful Language In The WORLD! Scala-crowd goes: O rly? Lisp-crowd goes: F-what?
- 11. F#“F# is a practical, functional-first languagethat lets you write simple codeto solve complex problems"
- 12. Complex Simplestatic Tree<KeyValuePair<A, bool>> DiffTree<A>(Tree<A> tree, Tree<A> tree2){ return XFoldTree( (A x, Func<Tree<A>, Tree<KeyValuePair<A, bool>>> l, Func<Tree<A>, Tree<KeyValuePair<A, bool>>> r, Tree<A> t) => (Tree<A> t2) => Node(new KeyValuePair<A, bool>(t2.Data, ReferenceEquals(t, t2)), l(t2.Left), r(t2.Right)), x1 => y => null, tree)(tree2);}
- 13. Complex Simple Tree<KeyValuePair<A, bool>> DiffTree<A>(Tree<A> tree, Tree<A> tree2){ XFoldTree( (A x, Func<Tree<A>, Tree<KeyValuePair<A, bool>>> l, Func<Tree<A>, Tree<KeyValuePair<A, bool>>> r, Tree<A> t) => (Tree<A> t2) => Node(new KeyValuePair<A, bool>(t2.Data, ReferenceEquals(t, t2)), l(t2.Left), r(t2.Right)), x1 => y => null, tree)(tree2);}
- 14. Complex Simple DiffTree ( tree, tree2){ XFoldTree( ( x, l, r, t) => (Tree<A> t2) => Node(new KeyValuePair<A, bool>(t2.Data, ReferenceEquals(t, t2)), l(t2.Left), r(t2.Right)), x1 => y => null, tree)(tree2);}
- 15. Complex Simple DiffTree ( tree, tree2){ XFoldTree( ( x, l, r, t, t2) => Node(new KeyValuePair<A, bool>(t2.Data, ReferenceEquals(t, t2)), l(t2.Left), r(t2.Right)), x1 => y => null, tree)(tree2);}
- 16. Complex Simple DiffTree ( tree, tree2){ XFoldTree( ( x, l, r, t, t2) => let (Node(x2,l2,r2)) = t2 Node((x2,t=t2), l l2, r r2)) (fun _ _ -> Leaf) tree tree2;}
- 17. Complex Simple DiffTree ( tree, tree2) XFoldTree( x, l, r, t, t2 =>let (Node(x2,l2,r2)) = t2Node((x2,t=t2), l l2, r r2)) (fun _ _ -> Leaf) tree tree2
- 18. Complex Simple let DiffTree ( tree, tree2) = XFoldTree(fun x, l, r, t, t2 ->let (Node(x2,l2,r2)) = t2Node((x2,t=t2), l l2, r r2)) (fun _ _ -> Leaf) tree tree2
- 19. Complex Simplelet DiffTree(tree, tree2) = XFoldTree(fun x, l, r, t, t2 -> let (Node(x2,l2,r2)) = t2 Node((x2,t=t2), l l2, r r2)) (fun _ _ -> Leaf) tree tree2
- 20. (Function) values in F#let ten = 10let square x = x*xlet squareList = List.map (fun n -> n*n)let addThree = (+) 3
- 21. (Function) values in F#let outer x = let inner y = printfn "outer + inner = %d" (x + y) inner 21let rec sum list = match list with | [] -> 0 | head::tail -> head + sum tail
- 22. Pattern matchinglet rec merge l1 l2 = Parallel pattern match l1, l2 with OR pattern | [], xs | xs, [] -> xs | x::xs, (y::_ as ys) when x <= y -> x::merge xs ys | xs, y::ys -> y::merge xs ys Named pattern Guarded pattern
- 23. F# data typesAlgebraic Data Types+ *
- 24. F# data types - Uniontype Shape = | Circle of float | Rectangle of float * float | Triangle of float * float
- 25. F# data types – Recursive union type BinTree = | Leaf of int | Node of BinTree * BinTree
- 26. F# data types - Option type Option<a> = | Some of a | None
- 27. F# data types - Option public Document getDocByID(int id); VSval getDocByID : int -> Document option
- 28. F# data types - Optionlet res = match getDocByID id with | None -> …handle not found… | Some(d) -> …do something with d…
- 29. F# data types - Listtype List<a> = | Nil | Cons of a*List<a> Nil + a*List<a>
- 30. F# data types - Listlet l1 = ["a"; "list"; "of"; "strings"]let l2 = "a"::"consed"::"list"::[]let l3 = [1..42]let l4 = [for i in l3 -> i*i]
- 31. Higher-order functionslet rec double l = match l with | [] -> List.empty | h::t -> h*2::double t
- 32. Higher-order functionslet rec length (l:string list) = match l with | [] -> List.empty | h::t -> h.Length::length t
- 33. Higher-order functionslet rec map f l = match l with | [] -> List.empty | h::t -> f(h)::map t
- 34. Higher-order functionsmap (fun x -> 2*x) listmap (fun (x:string) -> x.Length) list
- 35. Pipelining h(g(f(x))) VS x |> f |> g |> hPipeline operator
- 36. Function composition let f x = h(g(x)) VS let f = g >> h Composition operator
- 37. Function compositionlet double_then_sum = List.map ((*)2) >> List.reduce (+)
- 38. Synchronous -> Asynchronouslet getData (url:string) = let r = WebRequest.Create(url) let resp = r.GetResponse() use stream = resp.GetResponseStream() use reader = new StreamReader(stream) let data = reader.ReadToEnd() data
- 39. F# 3.0• Type Providers• Query Expressions• Triple-quoted strings
- 40. SummaryFunctional programming lets you Focus on the problem and less on noise Write consice and readable code Create composable programsF# gives you Access to the .NET framework Cross-platform Multiparadigm for solving real-world problems
- 41. So...Complex vs Simple Spaghetti vs Composability λ = Future? Headache vs Fun Lots of plumbing vs Logic
- 42. Jaywaychristian.jacobsen@jayway.com@chribbenFunctional Programming Sthlm User GroupJayway seminarsØredev

Be the first to comment