f# eye for the c# guy - seattle 2013
TRANSCRIPT
![Page 1: F# Eye For The C# Guy - Seattle 2013](https://reader033.vdocuments.net/reader033/viewer/2022060106/554911c3b4c90558458beb14/html5/thumbnails/1.jpg)
F# Eye 4 the C# GuyPhillip Trelford
@ptrelford
http://trelford.com/blog
![Page 2: F# Eye For The C# Guy - Seattle 2013](https://reader033.vdocuments.net/reader033/viewer/2022060106/554911c3b4c90558458beb14/html5/thumbnails/2.jpg)
Thoughtworks Tech RadarMarch 2012 - Languages
![Page 3: F# Eye For The C# Guy - Seattle 2013](https://reader033.vdocuments.net/reader033/viewer/2022060106/554911c3b4c90558458beb14/html5/thumbnails/3.jpg)
Thoughtworks Tech RadarMarch 2012 - Quotes
“F# is excellent at concisely expressing
business and domain logic.”
“Developers trying to achieve explicit business logic within an application may opt to
express their domain in F#
with the majority of plumbing code in C#.”
![Page 4: F# Eye For The C# Guy - Seattle 2013](https://reader033.vdocuments.net/reader033/viewer/2022060106/554911c3b4c90558458beb14/html5/thumbnails/4.jpg)
Visual F#
![Page 5: F# Eye For The C# Guy - Seattle 2013](https://reader033.vdocuments.net/reader033/viewer/2022060106/554911c3b4c90558458beb14/html5/thumbnails/5.jpg)
The F in F# is for FUN!
![Page 6: F# Eye For The C# Guy - Seattle 2013](https://reader033.vdocuments.net/reader033/viewer/2022060106/554911c3b4c90558458beb14/html5/thumbnails/6.jpg)
Halo 3 with F# Skills
![Page 7: F# Eye For The C# Guy - Seattle 2013](https://reader033.vdocuments.net/reader033/viewer/2022060106/554911c3b4c90558458beb14/html5/thumbnails/7.jpg)
XBLA: Path to Go – F# AI
![Page 8: F# Eye For The C# Guy - Seattle 2013](https://reader033.vdocuments.net/reader033/viewer/2022060106/554911c3b4c90558458beb14/html5/thumbnails/8.jpg)
Facebook: Monopoly
![Page 9: F# Eye For The C# Guy - Seattle 2013](https://reader033.vdocuments.net/reader033/viewer/2022060106/554911c3b4c90558458beb14/html5/thumbnails/9.jpg)
F#
• Statically Typed• Functional• Object Orientated• Open Source• .Net language• In Visual Studio
![Page 10: F# Eye For The C# Guy - Seattle 2013](https://reader033.vdocuments.net/reader033/viewer/2022060106/554911c3b4c90558458beb14/html5/thumbnails/10.jpg)
Functional Programming
• Idempotent Functions• Higher Order Functions• Pattern Matching
![Page 11: F# Eye For The C# Guy - Seattle 2013](https://reader033.vdocuments.net/reader033/viewer/2022060106/554911c3b4c90558458beb14/html5/thumbnails/11.jpg)
Functions - Excel
![Page 12: F# Eye For The C# Guy - Seattle 2013](https://reader033.vdocuments.net/reader033/viewer/2022060106/554911c3b4c90558458beb14/html5/thumbnails/12.jpg)
Higher Order Functions
F# Map/Reducelet map f xs = seq { for x in xs do yield f x }
let reduce f init items = let mutable current = init for item in items do current <- f current item current
C# Map/Reducepublic static IEnumerable<R> Map<T, R> (this IEnumerable<T> xs, Func<T, R> f){ foreach (var x in xs) yield return f(x);}
public static R Reduce<T, R> (this IEnumerable<T> xs, R init, Func<R, T, R> f){ var current = init; foreach (var x in xs) current = f(current, x); return current;}
![Page 13: F# Eye For The C# Guy - Seattle 2013](https://reader033.vdocuments.net/reader033/viewer/2022060106/554911c3b4c90558458beb14/html5/thumbnails/13.jpg)
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) { case 0: return "Sunday"; case 1: return "Monday"; case 2: return "Tuesday"; case 3: return "Wednesday"; case 4: return "Thursday"; case 5: return "Friday"; case 6: return "Saturday"; default: throw new ArgumentException("day"); }
![Page 14: F# Eye For The C# Guy - Seattle 2013](https://reader033.vdocuments.net/reader033/viewer/2022060106/554911c3b4c90558458beb14/html5/thumbnails/14.jpg)
DEMOS
![Page 15: F# Eye For The C# Guy - Seattle 2013](https://reader033.vdocuments.net/reader033/viewer/2022060106/554911c3b4c90558458beb14/html5/thumbnails/15.jpg)
Light Syntax: POCOs
F#type Person(name:string,age:int) =
/// Full name member person.Name = name
/// Age in years member person.Age = age
C#public class Person{ public Person(string name, int age) { _name = name; _age = age; }
private readonly string _name; private readonly int _age;
/// <summary> /// Full name /// </summary> public string Name { get { return _name; } }
/// <summary> /// Age in years /// </summary> public int Age { get { return _age; } }}
![Page 16: F# Eye For The C# Guy - Seattle 2013](https://reader033.vdocuments.net/reader033/viewer/2022060106/554911c3b4c90558458beb14/html5/thumbnails/16.jpg)
Light Syntax: DI
C#public class VerySimpleStockTraderImpl : IAutomatedStockTrader{ private readonly IStockAnalysisService analysisService; private readonly IOnlineBrokerageService brokerageService;
public VerySimpleStockTraderImpl( IStockAnalysisService analysisService, IOnlineBrokerageService brokerageService) { this.analysisService = analysisService; this.brokerageService = brokerageService; }
public void ExecuteTrades() { // ... }}
F#type VerySimpleStockTraderImpl (analysisService:IStockAnalysisService, brokerageService:IOnlineBrokerageService) = member this.ExecuteTrades() = () // ...
![Page 17: F# Eye For The C# Guy - Seattle 2013](https://reader033.vdocuments.net/reader033/viewer/2022060106/554911c3b4c90558458beb14/html5/thumbnails/17.jpg)
Unit Testing
F# NUnitmodule MathTest =
open NUnit.Framework
let [<Test>] ``2 + 2 should equal 4``() = Assert.AreEqual(2 + 2, 4)
C# NUnitusing NUnit.Framework;
[TestFixture]public class MathTest{ [Test] public void TwoPlusTwoShouldEqualFour() { Assert.AreEqual(2 + 2, 4); }}
![Page 18: F# Eye For The C# Guy - Seattle 2013](https://reader033.vdocuments.net/reader033/viewer/2022060106/554911c3b4c90558458beb14/html5/thumbnails/18.jpg)
BDD
![Page 19: F# Eye For The C# Guy - Seattle 2013](https://reader033.vdocuments.net/reader033/viewer/2022060106/554911c3b4c90558458beb14/html5/thumbnails/19.jpg)
Units of Measure
![Page 20: F# Eye For The C# Guy - Seattle 2013](https://reader033.vdocuments.net/reader033/viewer/2022060106/554911c3b4c90558458beb14/html5/thumbnails/20.jpg)
Units in Cells
type formula = | Neg of formula | Exp of formula * formula | ArithmeticOp of formula * arithmetic * formula | LogicalOp of formula * logical * formula | Num of UnitValue | Ref of int * int | Range of int * int * int * int | Fun of string * formula list
![Page 21: F# Eye For The C# Guy - Seattle 2013](https://reader033.vdocuments.net/reader033/viewer/2022060106/554911c3b4c90558458beb14/html5/thumbnails/21.jpg)
F# 3.0Type Providers
![Page 22: F# Eye For The C# Guy - Seattle 2013](https://reader033.vdocuments.net/reader033/viewer/2022060106/554911c3b4c90558458beb14/html5/thumbnails/22.jpg)
SUMMARY
![Page 23: F# Eye For The C# Guy - Seattle 2013](https://reader033.vdocuments.net/reader033/viewer/2022060106/554911c3b4c90558458beb14/html5/thumbnails/23.jpg)
F# Books
![Page 24: F# Eye For The C# Guy - Seattle 2013](https://reader033.vdocuments.net/reader033/viewer/2022060106/554911c3b4c90558458beb14/html5/thumbnails/24.jpg)
Meet the F#ers Twitter #fsharp
@rickasaurus
@tomaspetricek
@jonharrop
![Page 25: F# Eye For The C# Guy - Seattle 2013](https://reader033.vdocuments.net/reader033/viewer/2022060106/554911c3b4c90558458beb14/html5/thumbnails/25.jpg)
@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 .net devs. #fsharp
![Page 26: F# Eye For The C# Guy - Seattle 2013](https://reader033.vdocuments.net/reader033/viewer/2022060106/554911c3b4c90558458beb14/html5/thumbnails/26.jpg)
Q & A
Links
• http://fsharp.org• http://fssnip.net• http://tryfsharp.org
Connect
• @ptrelford• [email protected]• http://trelford.com/blog