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.
Getting the MVVM kicked out of your F#'n Monads  Richard Minerich F# MVP of the Year Senior Researcher, Bayard Rock @Ricka...
Time Warp back to 6 th  Grade <ul><li>1 + (2 + 3) = 6 and (1 + 2) + 3 = 6 </li></ul><ul><li>and </li></ul><ul><li>1 * (2 *...
What about functions? <ul><li>let addOne x = x + 1 </li></ul><ul><li>let addTwo x = x + 2 </li></ul><ul><li>let addThree x...
>> is like add for functions <ul><li>let addOne x = x + 1 </li></ul><ul><li>let addTwo x = x + 2 </li></ul><ul><li>let add...
5 + 0 = 5 and 3 * 1  = 3 <ul><li>What would be the same thing for a function? </li></ul>
5 + 0 = 5 and 3 * 1  = 3 <ul><li>What would be the same thing for a function? </li></ul><ul><li>let id f = f </li></ul><ul...
functions are like numbers <ul><li>Just like (2 + 3) + 4 = 2 + (3 + 4) </li></ul><ul><li>let addSix = (addOne >> addTwo) >...
(2 / 3) / 4 isn’t 2 / (3 / 4) but,  <ul><li>let divByTwo x = x / 2 </li></ul><ul><li>let divByThree x = x / 3 </li></ul><u...
(1 - 2) - 3 isn’t 1 - (2 - 3) but, <ul><li>let minusOne x = x - 1 </li></ul><ul><li>let minusTwo x = x - 2 </li></ul><ul><...
(1 - 2) - 3 isn’t 1 - (2 - 3) cont. <ul><li>let minusSix = minusTwo >> minusThree >> minusOne </li></ul><ul><li>Works grea...
School’s out! <ul><li>First class functions are in! </li></ul>
One Style of Abstraction <ul><li>let ten = [1; 2; 3; 4] |> List.fold (fun x y -> x + y) 0 </li></ul><ul><li>let ten = [1; ...
It works with functions too! <ul><li>let ten =  </li></ul><ul><li>[addOne; addTwo; addThree; addFour]  </li></ul><ul><li>|...
Computation Expressions <ul><li>Will Blow Your Mind </li></ul>
Computation Expressions! <ul><li>-> Each line is a lambda. </li></ul><ul><li>-> In normal class methods you dispatch on ty...
What can you manipulate? <ul><li>Binding, Yielding and Returning </li></ul><ul><li>For and While </li></ul><ul><li>Use, Tr...
Let’s take a look at a simple CE <ul><li>type MultBuilder () =  </li></ul><ul><li>member t.Combine (x,y) = x * y </li></ul...
It goes much deeper. <ul><li>Return – Stuff something in a container </li></ul><ul><li>Bind – Pull it out  </li></ul><ul><...
Option <ul><li>type Option<'a> = | Some of 'a | None </li></ul><ul><li>Most easily used as: </li></ul><ul><li>match x with...
Maybe <ul><li>Maybe allows us to short circuit when something goes wrong, instead of matching again and again. </li></ul>
“ F# 2.0 is a book that assumes you are a professional,  and as such, does not waste your time with a lot of fluff.”
Check out F#! <ul><li>Blog:  RichardMinerich.com </li></ul><ul><li>Twitter:  @Rickasaurus </li></ul><ul><li>F# Community N...
We thank the following companies for their gracious sponsorship Platinum Sponsor Gold Sponsors Silver Sponsors
Upcoming SlideShare
Loading in …5
×

Getting the MVVM Kicked Out of Your F#'n Monads

4,780 views

Published on

Published in: Technology
  • Be the first to comment

Getting the MVVM Kicked Out of Your F#'n Monads

  1. 1. Getting the MVVM kicked out of your F#'n Monads Richard Minerich F# MVP of the Year Senior Researcher, Bayard Rock @Rickasaurus / [email_address] Fill this space with whatever you want (graphic, logo, whatever)
  2. 2. Time Warp back to 6 th Grade <ul><li>1 + (2 + 3) = 6 and (1 + 2) + 3 = 6 </li></ul><ul><li>and </li></ul><ul><li>1 * (2 * 3) = (1 * 2) * 3 </li></ul>
  3. 3. What about functions? <ul><li>let addOne x = x + 1 </li></ul><ul><li>let addTwo x = x + 2 </li></ul><ul><li>let addThree x = x + 3 </li></ul><ul><li>All are int -> int </li></ul><ul><li>let addSix x = addOne(addTwo(addThree(x))) </li></ul>
  4. 4. >> is like add for functions <ul><li>let addOne x = x + 1 </li></ul><ul><li>let addTwo x = x + 2 </li></ul><ul><li>let addThree x = x + 3 </li></ul><ul><li>All are int -> int </li></ul><ul><li>let addSix = addOne >> addTwo >> addThree </li></ul>
  5. 5. 5 + 0 = 5 and 3 * 1 = 3 <ul><li>What would be the same thing for a function? </li></ul>
  6. 6. 5 + 0 = 5 and 3 * 1 = 3 <ul><li>What would be the same thing for a function? </li></ul><ul><li>let id f = f </li></ul><ul><li>So, </li></ul><ul><li>addFive >> id = addFive </li></ul>
  7. 7. functions are like numbers <ul><li>Just like (2 + 3) + 4 = 2 + (3 + 4) </li></ul><ul><li>let addSix = (addOne >> addTwo) >> addThree </li></ul><ul><li>is the same as </li></ul><ul><li>let addSix = addOne >> (addTwo >> addThree) </li></ul><ul><li>Just like 6 = 0 + 6 </li></ul><ul><li>addSix = id >> addSix </li></ul>
  8. 8. (2 / 3) / 4 isn’t 2 / (3 / 4) but, <ul><li>let divByTwo x = x / 2 </li></ul><ul><li>let divByThree x = x / 3 </li></ul><ul><li>let divByFour x = x / 4 </li></ul><ul><li>let divByTwentyFour = (divByTwo >> divByThree) >> divByFour </li></ul><ul><li>is the same as </li></ul><ul><li>let divByTwentyFour = divByTwo >> (divByThree >> divByFour) </li></ul><ul><li>Why? </li></ul>
  9. 9. (1 - 2) - 3 isn’t 1 - (2 - 3) but, <ul><li>let minusOne x = x - 1 </li></ul><ul><li>let minusTwo x = x - 2 </li></ul><ul><li>let minusThree x = x - 3 </li></ul><ul><li>let minusSix = (minusOne >> minusTwo) >> minusThree </li></ul><ul><li>is the same as </li></ul><ul><li>let minusSix = minusOne >> (minusTwo >> minusThree) </li></ul><ul><li>Why? </li></ul>
  10. 10. (1 - 2) - 3 isn’t 1 - (2 - 3) cont. <ul><li>let minusSix = minusTwo >> minusThree >> minusOne </li></ul><ul><li>Works great. But consider.. </li></ul><ul><li>let minusSix = </li></ul><ul><li>timesTwo >> divTwo >> minusThree >> minusThree </li></ul><ul><li>let ohNo = </li></ul><ul><li> minusThree >> divTwo >> minusThree >> timesTwo </li></ul>
  11. 11. School’s out! <ul><li>First class functions are in! </li></ul>
  12. 12. One Style of Abstraction <ul><li>let ten = [1; 2; 3; 4] |> List.fold (fun x y -> x + y) 0 </li></ul><ul><li>let ten = [1; 2; 3; 4] |> List.reduce (fun x y -> x + y) </li></ul><ul><li>let ten = [1; 2; 3; 4] |> List.reduce (+) </li></ul><ul><li>let ten = [1; 2; 3; 4] |> List.sum </li></ul><ul><li>Fold – You provide the identity </li></ul><ul><li>Reduce – No identity needed </li></ul><ul><li>Reduce – Actually, just the operator is good </li></ul><ul><li>Sum – Complete package, you provide nothing </li></ul>
  13. 13. It works with functions too! <ul><li>let ten = </li></ul><ul><li>[addOne; addTwo; addThree; addFour] </li></ul><ul><li>|> List.fold (fun x f -> f x) 0 </li></ul><ul><li>let ten = </li></ul><ul><li>[addOne; addTwo; addThree; addFour] </li></ul><ul><li>|> List.reduce (>>) </li></ul><ul><li><| 0 </li></ul><ul><li>But how do we abstract ideas like these over the inside of functions? </li></ul>
  14. 14. Computation Expressions <ul><li>Will Blow Your Mind </li></ul>
  15. 15. Computation Expressions! <ul><li>-> Each line is a lambda. </li></ul><ul><li>-> In normal class methods you dispatch on type, with computation expressions you dispatch on language constructs. </li></ul>
  16. 16. What can you manipulate? <ul><li>Binding, Yielding and Returning </li></ul><ul><li>For and While </li></ul><ul><li>Use, Try-With and Try-Finally </li></ul><ul><li>Per-function </li></ul><ul><li>The Entire Computation </li></ul><ul><li>The computation can be manipulated at all of these levels. </li></ul>
  17. 17. Let’s take a look at a simple CE <ul><li>type MultBuilder () = </li></ul><ul><li>member t.Combine (x,y) = x * y </li></ul><ul><li>member t.Yield (x) = x </li></ul><ul><li>member x.Delay(f) = f() </li></ul><ul><li>let mult = new MultBuilder() </li></ul><ul><li>mult {yield 2; yield 3} </li></ul>
  18. 18. It goes much deeper. <ul><li>Return – Stuff something in a container </li></ul><ul><li>Bind – Pull it out </li></ul><ul><li>(or decide what to do it’s empty) </li></ul><ul><li>Computation expressions allow us to do this behind the scenes in an elegant way. </li></ul>
  19. 19. Option <ul><li>type Option<'a> = | Some of 'a | None </li></ul><ul><li>Most easily used as: </li></ul><ul><li>match x with </li></ul><ul><li>| Some x -> x </li></ul><ul><li>| None -> raise “Oh god, what now!” </li></ul><ul><li>But we can do better. </li></ul>
  20. 20. Maybe <ul><li>Maybe allows us to short circuit when something goes wrong, instead of matching again and again. </li></ul>
  21. 21. “ F# 2.0 is a book that assumes you are a professional, and as such, does not waste your time with a lot of fluff.”
  22. 22. Check out F#! <ul><li>Blog: RichardMinerich.com </li></ul><ul><li>Twitter: @Rickasaurus </li></ul><ul><li>F# Community News: FSharpCentral.com </li></ul><ul><li>And the NYC F# User Group: </li></ul><ul><li>http://www.meetup.com/nyc-fsharp </li></ul><ul><li>We meet monthly right here! </li></ul>
  23. 23. We thank the following companies for their gracious sponsorship Platinum Sponsor Gold Sponsors Silver Sponsors

×