Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Functional programming and F#<br />Sanko.net meeting 8.6.2011<br />
Agenda<br />Functional programming from c# perspective, Linq principles<br />Functional programming in general<br />F# and...
Agenda<br />Functional programming from c# perspective, Linq principles<br />Functional programming in general<br />F# and...
This happens, when you Powerpoint without test harness! <br />Lets kick the PowerPoint and.... Correct the agenda using......
F#?<br />This happens, when you Powerpoint without test harness! <br />Lets kick the PowerPoint and.... Correct the agenda...
F#?<br />This happens, when you Powerpoint without test harness! <br />Lets kick the PowerPoint and.... Correct the agenda...
Demo.... <br />Source available @ github: <br />https://github.com/ramik/Demo/blob/master/FunctionalTutorial/CSharpExample...
Why F#?<br />
Why F#?<br />Well, simply because its fun!<br />
Why F#?<br />Well, simply because its fun!<br />(fun is reserved keyword, for      expression)!<br />
F# has / is:<br />Succint<br />Closures<br />Functional<br />Generics<br />Discrimated unions<br />.net official language ...
F# has / is:<br />But for now, lets <br />focus on this!<br />Functional<br />
Well, what is functional programming?<br /><ul><li>Immutable constructs
Functions as first class ”citizens”
Recursion
No mutable state </li></ul>Many other concepts apply, but these are ones <br />to focus in this presentation <br />
Immutability:<br />Object cannot be changed after creation<br />In C#, mark fields as readonly<br />No mutable state  no ...
Functions as first class citizens:<br />Functions can be passed as normal parameters <br />Composition<br />Higher order f...
Recursion:<br />In functional programming, no iteration or ”looping”<br />Recursion is very important concept<br />
Recursion:<br />In functional programming, no iteration or ”looping”<br />Recursion is very important concept<br /><ul><li...
Recursion:<br />In functional programming, no iteration or ”looping”<br />Recursion is very important concept<br /><ul><li...
Upcoming SlideShare
Loading in …5
×

F# and functional programming

1,267 views

Published on

Presentation was given june 2011 in sanko.net meeting

Published in: Technology
  • Be the first to comment

  • Be the first to like this

F# and functional programming

  1. 1. Functional programming and F#<br />Sanko.net meeting 8.6.2011<br />
  2. 2. Agenda<br />Functional programming from c# perspective, Linq principles<br />Functional programming in general<br />F# and C# interoperability<br />F# examples: ’basic’ stuff<br />F# vs. C# <br />
  3. 3. Agenda<br />Functional programming from c# perspective, Linq principles<br />Functional programming in general<br />F# and C# interoperability<br />F# examples: ’basic’ stuff<br />F# vs. C# <br />Eh?<br />There’s a bug in the Agenda!!!<br />Wrong order and names missing!<br />
  4. 4. This happens, when you Powerpoint without test harness! <br />Lets kick the PowerPoint and.... Correct the agenda using....<br />
  5. 5. F#?<br />This happens, when you Powerpoint without test harness! <br />Lets kick the PowerPoint and.... Correct the agenda using....<br />
  6. 6. F#?<br />This happens, when you Powerpoint without test harness! <br />Lets kick the PowerPoint and.... Correct the agenda using....<br />Java guy? Great!<br />
  7. 7. Demo.... <br />Source available @ github: <br />https://github.com/ramik/Demo/blob/master/FunctionalTutorial/CSharpExamples/PresisDemo/SlideDemo.fs<br />And if you don’t have internet access, snapshotted source just for you<br />module SlideDemo<br />open System;<br />type PresentationKeeper(name: string, employer : string) = <br /> member lollis.name = name<br /> member fuulis.employer = employer<br /> override this.ToString() = name + ", " + employer<br />let Rami = PresentationKeeper("Rami Karjalainen", "Reaktor")<br />let Tuomas = PresentationKeeper("Tuomas Hietanen", "Basware")<br />let topics = [ (2, "Functional programming from c# perspective, Linq principles", Tuomas);<br /> (1, "Functional programming in general", Rami);<br /> (3, "F# examples: ’basic’ stuff", Rami);<br /> (4, "F# and C# interoperability", Rami);<br /> (5, "F# vs. C#", Tuomas) ]<br />let formatTopic topic keeper = String.Format ("{0} ({1})", topic, keeper.ToString())<br />let pimpTheList = topics |> Seq.sortBy (fun (prio,_,_) -> prio) <br /> |> Seq.map (fun (_, a, b) -> a,b)<br /> |> Seq.map (fun x -> (formatTopic (fst x) (snd x)))<br />let printPimped x = x |> Seq.iter (fun c -> printfn "%s" c)<br />
  8. 8. Why F#?<br />
  9. 9. Why F#?<br />Well, simply because its fun!<br />
  10. 10. Why F#?<br />Well, simply because its fun!<br />(fun is reserved keyword, for expression)!<br />
  11. 11. F# has / is:<br />Succint<br />Closures<br />Functional<br />Generics<br />Discrimated unions<br />.net official language (v4  )<br />Pattern matching<br />Tail recursion optimization <br />Tuples<br />Immutable by default<br />asynchronous workflows<br />Very expressive<br />Interoperable<br />Type inference<br />Classes<br />Infinite lists etc. (laziness) <br />Strongly typed<br />Hybrid (oo, imperative)<br />Lambda expressions (anon func)<br />REPL (interactive)<br />OCaml<br />
  12. 12. F# has / is:<br />But for now, lets <br />focus on this!<br />Functional<br />
  13. 13. Well, what is functional programming?<br /><ul><li>Immutable constructs
  14. 14. Functions as first class ”citizens”
  15. 15. Recursion
  16. 16. No mutable state </li></ul>Many other concepts apply, but these are ones <br />to focus in this presentation <br />
  17. 17. Immutability:<br />Object cannot be changed after creation<br />In C#, mark fields as readonly<br />No mutable state  no local variables<br />
  18. 18. Functions as first class citizens:<br />Functions can be passed as normal parameters <br />Composition<br />Higher order functions<br /><ul><li>Takes a function as param</li></ul>and/or<br /><ul><li>Returns a function as output</li></li></ul><li>Functions as first class citizens:<br />Functions can be passed as normal parameters <br />Composition<br />Higher order functions<br /><ul><li>Takes a function as param</li></ul>and/or<br /><ul><li>Returns a function as output</li></ul>Tuomas will cover the deeps of the function theory later in the session<br />
  19. 19. Recursion:<br />In functional programming, no iteration or ”looping”<br />Recursion is very important concept<br />
  20. 20. Recursion:<br />In functional programming, no iteration or ”looping”<br />Recursion is very important concept<br /><ul><li>Recursion is very important, </li></ul>as without it ....<br />
  21. 21. Recursion:<br />In functional programming, no iteration or ”looping”<br />Recursion is very important concept<br /><ul><li>Recursion is very important, </li></ul>as without it ....<br />
  22. 22. Recursion:<br />In functional programming, no iteration or ”looping”<br />Recursion is very important concept<br /><ul><li>Recursion is very important, </li></ul>as without it ....<br />Tail recursion or stack says bye!<br />
  23. 23. Time to switch to Visual Studio!<br />(for good this time)<br />

×