F# Eye 4 the C# GuyPhillip Trelford@ptrelfordhttp://trelford.com/blog
Thoughtworks Tech RadarJuly 2011
Visual F#
The F in F# standsfor FUN
Halo 3 with F# Skills
XBLA: Path to Go – F# AI
F#Strongly TypedFunctionalObject OrientatedOpen Source.Net languageIn Visual Studio
Functional ProgrammingPure FunctionsHigher Order FunctionsPattern Matching
Pure Functions - Excel
Higher Order FunctionsF# Map/Reduceletmapf xs = seq { for x inxsdoyield f x     }letreducefinititems =letmutablecurrent = initfor item in items docurrent <- f current itemcurrentC# Map/ReducepublicstaticIEnumerable<R> Map<T, R>    (thisIEnumerable<T> xs,Func<T, R> f){foreach (var x in xs)yieldreturn f(x);}publicstatic RReduce<T, R>    (thisIEnumerable<T> xs,     R init,Func<R, T, R> f){varcurrent = init;foreach (var x in xs)current = f(current, x);return current;}
Pattern MatchingF#match day with| 0 ->"Sunday"| 1 ->"Monday"| 2 ->"Tuesday"| 3 ->"Wednesday"| 4 ->"Thursday"| 5 ->"Friday"| 6 ->"Saturday"| _ –>invalidArg"Invalid day"C#switch (day) {  case0: return"Sunday";  case1: return"Monday";  case2: return"Tuesday";  case3: return"Wednesday";  case4: return"Thursday";  case5: return"Friday";  case6: return"Saturday";  default:thrownewArgumentException("day");           }
demos
Light SyntaxF#type Person(name:string,age:int) =/// Full namememberperson.Name = name/// Age in yearsmemberperson.Age = ageC#publicclassPerson{public Person(string name, int age)    {        _name = name;        _age = age;    }privatereadonlystring _name;privatereadonlyint _age;///<summary>/// Full name///</summary>publicstring Name    {get { return _name; }    }///<summary>/// Age in years///</summary>publicint Age    {get { return _age; }    }}
Unit Testing toExplorative TestingF# NUnitopenNUnit.Framework[<TestFixture>]moduleMathTest =    [<Test>]let ``2 + 2 should equal 4`` () =Assert.AreEqual(2 + 2, 4)C# NUnitusingNUnit.Framework;[TestFixture]publicclassTest{    [Test]publicvoidTwoPlusTwoShouldEqualFour(){Assert.AreEqual(2 + 2, 4);    }}
Domain Model - POStypeCode = stringtype Name = stringtype Price = decimaltype Product =  Product of Code * Name * Pricetype Quantity = decimaltypeSaleLineItem =  Product * Quantity
F# 3.0 (Beta)Type Providers
Units of Measure
Units in CellstypearithmeticOp =  Add | Sub | Mul | DivtypelogicalOp = Eq| Lt | Gt | Le | Ge | Netype formula =| Negof formula| Expof formula * formula| ArithmeticOpof     formula * arithmeticOp * formula| LogicalOpof     formula * logicalOp * formula| NumofUnitValue| Ref ofint * int| Range ofint * int * int * int| Fun of string * formula list
SUMMARY
TIOBE Index August 2011 - F# enters Top 20
F# Jobs
Meet the F#ersTwitter #fsharp
F# Books
@jbandi#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
Q & ALinkshttp://fsharp.nethttp://fssnip.nethttp://tryfsharp.orgContact@ptrelfordphil@trelford.comhttp://trelford.com/blog

F# Eye 4 the C# Guy