• Save
F# Eye 4 the C# Guy
Upcoming SlideShare
Loading in...5
×
 

F# Eye 4 the C# Guy

on

  • 7,573 views

 

Statistics

Views

Total Views
7,573
Views on SlideShare
6,525
Embed Views
1,048

Actions

Likes
4
Downloads
0
Comments
0

9 Embeds 1,048

http://www.trelford.com 469
http://trelford.com 402
http://www.redditmedia.com 159
http://blogs.msdn.com 5
http://us-w1.rockmelt.com 5
http://a0.twimg.com 3
http://www.zhuaxia.com 3
https://twimg0-a.akamaihd.net 1
http://www.google.ie 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

F# Eye 4 the C# Guy F# Eye 4 the C# Guy Presentation Transcript

  • F# Eye 4 the C# Guy
    Phillip Trelford
    @ptrelford
    http://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 Typed
    Functional
    Object Orientated
    Open Source
    .Net language
    In Visual Studio
  • Functional Programming
    Pure Functions
    Higher Order Functions
    Pattern Matching
  • Pure Functions - Excel
  • Higher Order Functions
    F# Map/Reduce
    letmapf xs = seq {
    for x inxsdo
    yield f x
    }
    letreducefinititems =
    letmutablecurrent = init
    for item in items do
    current <- f current item
    current
    C# Map/Reduce
    publicstatic
    IEnumerable<R> Map<T, R>
    (thisIEnumerable<T> xs,
    Func<T, R> f)
    {
    foreach (var x in xs)
    yieldreturn f(x);
    }
    publicstatic R
    Reduce<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 Matching
    F#
    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:
    thrownew
    ArgumentException("day");
    }
  • demos
  • Light Syntax
    F#
    type Person(name:string,age:int) =
    /// Full name
    memberperson.Name = name
    /// Age in years
    memberperson.Age = age
    C#
    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 Testing
    F# NUnit
    openNUnit.Framework
    [<TestFixture>]
    moduleMathTest =
    [<Test>]
    let ``2 + 2 should equal 4`` () =
    Assert.AreEqual(2 + 2, 4)
    C# NUnit
    usingNUnit.Framework;
    [TestFixture]
    publicclassTest
    {
    [Test]
    publicvoid
    TwoPlusTwoShouldEqualFour()
    {
    Assert.AreEqual(2 + 2, 4);
    }
    }
  • Domain Model - POS
    typeCode = string
    type Name = string
    type Price = decimal
    type Product =
    Product of Code * Name * Price
    type Quantity = decimal
    typeSaleLineItem =
    Product * Quantity
  • F# 3.0 (Beta)Type Providers
  • Units of Measure
  • Units in Cells
    typearithmeticOp =
    Add | Sub | Mul | Div
    typelogicalOp =
    Eq| Lt | Gt | Le | Ge | Ne
    type 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 & A
    Links
    http://fsharp.net
    http://fssnip.net
    http://tryfsharp.org
    Contact
    @ptrelford
    phil@trelford.com
    http://trelford.com/blog