Your SlideShare is downloading. ×
F# Eye 4 the C# Guy<br />Phillip Trelford<br />@ptrelford<br />http://trelford.com/blog<br />
Thoughtworks Tech RadarJuly 2011<br />
Visual F#<br />
The F in F# standsfor FUN<br />
Halo 3 with F# Skills<br />
XBLA: Path to Go – F# AI<br />
F#<br />Strongly Typed<br />Functional<br />Object Orientated<br />Open Source<br />.Net language<br />In Visual Studio<br />
Functional Programming<br />Pure Functions<br />Higher Order Functions<br />Pattern Matching<br />
Pure Functions - Excel<br />
Higher Order Functions<br />F# Map/Reduce<br />letmapf xs = seq { <br />for x inxsdo<br />yield f x <br />    }<br />letre...
Pattern Matching<br />F#<br />match day with<br />| 0 ->"Sunday"<br />| 1 ->"Monday"<br />| 2 ->"Tuesday"<br />| 3 ->"Wedn...
demos<br />
Light Syntax<br />F#<br />type Person(name:string,age:int) =<br />/// Full name<br />memberperson.Name = name<br />/// Age...
Unit Testing toExplorative Testing<br />F# NUnit<br />openNUnit.Framework<br />[<TestFixture>]<br />moduleMathTest =<br />...
Domain Model - POS<br />typeCode = string<br />type Name = string<br />type Price = decimal<br />type Product = <br /> Pro...
F# 3.0 (Beta)Type Providers<br />
Units of Measure<br />
Units in Cells<br />typearithmeticOp = <br /> Add | Sub | Mul | Div<br />typelogicalOp = <br />Eq| Lt | Gt | Le | Ge | Ne<...
SUMMARY<br />
TIOBE Index August 2011 - F# enters Top 20<br />
F# Jobs<br />
Meet the F#ersTwitter #fsharp<br />
F# Books<br />
@jbandi<br />#chtd Quote from "future of .net" Have a look at F# for two days and you will find yourself two years ahead o...
Q & A<br />Links<br />http://fsharp.net<br />http://fssnip.net<br />http://tryfsharp.org<br />Contact<br />@ptrelford<br /...
Upcoming SlideShare
Loading in...5
×

F# Eye 4 the C# Guy

7,091

Published on

Published in: Technology
0 Comments
5 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
7,091
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
0
Comments
0
Likes
5
Embeds 0
No embeds

No notes for slide

Transcript of "F# Eye 4 the C# Guy"

  1. 1. F# Eye 4 the C# Guy<br />Phillip Trelford<br />@ptrelford<br />http://trelford.com/blog<br />
  2. 2.
  3. 3. Thoughtworks Tech RadarJuly 2011<br />
  4. 4. Visual F#<br />
  5. 5. The F in F# standsfor FUN<br />
  6. 6. Halo 3 with F# Skills<br />
  7. 7. XBLA: Path to Go – F# AI<br />
  8. 8. F#<br />Strongly Typed<br />Functional<br />Object Orientated<br />Open Source<br />.Net language<br />In Visual Studio<br />
  9. 9. Functional Programming<br />Pure Functions<br />Higher Order Functions<br />Pattern Matching<br />
  10. 10. Pure Functions - Excel<br />
  11. 11. Higher Order Functions<br />F# Map/Reduce<br />letmapf xs = seq { <br />for x inxsdo<br />yield f x <br /> }<br />letreducefinititems =<br />letmutablecurrent = init<br />for item in items do<br />current <- f current item<br />current<br />C# Map/Reduce<br />publicstatic<br />IEnumerable<R> Map<T, R><br /> (thisIEnumerable<T> xs,<br />Func<T, R> f)<br />{<br />foreach (var x in xs)<br />yieldreturn f(x);<br />}<br />publicstatic R<br />Reduce<T, R><br /> (thisIEnumerable<T> xs,<br /> R init,<br />Func<R, T, R> f)<br />{<br />varcurrent = init;<br />foreach (var x in xs)<br />current = f(current, x);<br />return current;<br />}<br />
  12. 12. Pattern Matching<br />F#<br />match day with<br />| 0 ->"Sunday"<br />| 1 ->"Monday"<br />| 2 ->"Tuesday"<br />| 3 ->"Wednesday"<br />| 4 ->"Thursday"<br />| 5 ->"Friday"<br />| 6 ->"Saturday"<br />| _ –><br />invalidArg"Invalid day"<br />C#<br />switch (day) {<br /> case0: return"Sunday";<br /> case1: return"Monday";<br /> case2: return"Tuesday";<br /> case3: return"Wednesday";<br /> case4: return"Thursday";<br /> case5: return"Friday";<br /> case6: return"Saturday";<br /> default:<br />thrownew<br />ArgumentException("day"); <br />}<br />
  13. 13. demos<br />
  14. 14. Light Syntax<br />F#<br />type Person(name:string,age:int) =<br />/// Full name<br />memberperson.Name = name<br />/// Age in years<br />memberperson.Age = age<br />C#<br />publicclassPerson<br />{<br />public Person(string name, int age)<br /> {<br /> _name = name;<br /> _age = age;<br /> }<br />privatereadonlystring _name;<br />privatereadonlyint _age;<br />///<summary><br />/// Full name<br />///</summary><br />publicstring Name<br /> {<br />get { return _name; }<br /> }<br />///<summary><br />/// Age in years<br />///</summary><br />publicint Age<br /> {<br />get { return _age; }<br /> }<br />}<br />
  15. 15. Unit Testing toExplorative Testing<br />F# NUnit<br />openNUnit.Framework<br />[<TestFixture>]<br />moduleMathTest =<br /> [<Test>]<br />let ``2 + 2 should equal 4`` () =<br />Assert.AreEqual(2 + 2, 4)<br />C# NUnit<br />usingNUnit.Framework;<br />[TestFixture]<br />publicclassTest<br />{<br /> [Test]<br />publicvoid<br />TwoPlusTwoShouldEqualFour()<br />{<br />Assert.AreEqual(2 + 2, 4);<br /> }<br />}<br />
  16. 16. Domain Model - POS<br />typeCode = string<br />type Name = string<br />type Price = decimal<br />type Product = <br /> Product of Code * Name * Price<br />type Quantity = decimal<br />typeSaleLineItem = <br /> Product * Quantity<br />
  17. 17. F# 3.0 (Beta)Type Providers<br />
  18. 18. Units of Measure<br />
  19. 19. Units in Cells<br />typearithmeticOp = <br /> Add | Sub | Mul | Div<br />typelogicalOp = <br />Eq| Lt | Gt | Le | Ge | Ne<br />type formula =<br />| Negof formula<br />| Expof formula * formula<br />| ArithmeticOpof<br /> formula * arithmeticOp * formula<br />| LogicalOpof<br /> formula * logicalOp * formula<br />| NumofUnitValue<br />| Ref ofint * int<br />| Range ofint * int * int * int<br />| Fun of string * formula list<br />
  20. 20. SUMMARY<br />
  21. 21. TIOBE Index August 2011 - F# enters Top 20<br />
  22. 22. F# Jobs<br />
  23. 23. Meet the F#ersTwitter #fsharp<br />
  24. 24. F# Books<br />
  25. 25. @jbandi<br />#chtd Quote from "future of .net" Have a look at F# for two days and you will find yourself two years ahead of your peer .netdevs. #fsharp<br />
  26. 26. Q & A<br />Links<br />http://fsharp.net<br />http://fssnip.net<br />http://tryfsharp.org<br />Contact<br />@ptrelford<br />phil@trelford.com<br />http://trelford.com/blog<br />

×