1 / 26

F# Eye 4 the C# Guy

F# Eye 4 the C# Guy. Phillip Trelford @ ptrelford http://trelford.com/blog. Thoughtworks Tech Radar March 2012 - Languages. “F# is excellent at concisely expressing business and domain logic.” “Developers trying to achieve explicit business logic within an application may opt to

ludwig
Download Presentation

F# Eye 4 the C# Guy

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. F# Eye 4 the C# Guy Phillip Trelford @ptrelford http://trelford.com/blog

  2. Thoughtworks Tech RadarMarch 2012 - Languages

  3. “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#.” Thoughtworks Tech RadarMarch 2012 - Quotes

  4. Visual F#

  5. The F in F# is for FUN!

  6. Halo 3 with F# Skills

  7. XBLA: Path to Go – F# AI

  8. Facebook: Monopoly

  9. F# Statically Typed Functional Object Orientated Open Source .Net language In Visual Studio

  10. Idempotent Functions • Higher Order Functions • Pattern Matching Functional Programming

  11. Functions - Excel

  12. F# Map/Reduce 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; } letmapf xs = seq { for x inxsdo yield f x } letreducefinititems = letmutablecurrent = init for item in items do current <- f current item current Higher Order Functions

  13. F# 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"); } match day with | 0 ->"Sunday" | 1 ->"Monday" | 2 ->"Tuesday" | 3 ->"Wednesday" | 4 ->"Thursday" | 5 ->"Friday" | 6 ->"Saturday" | _ –> invalidArg"Invalid day" Pattern Matching

  14. demos

  15. F# 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; } } } type Person(name:string,age:int) = /// Full name memberperson.Name = name /// Age in years memberperson.Age = age Light Syntax: POCOs

  16. C# F# typeVerySimpleStockTraderImpl (analysisService:IStockAnalysisService, brokerageService:IOnlineBrokerageService) = memberthis.ExecuteTrades() = () // ... publicclassVerySimpleStockTraderImpl : IAutomatedStockTrader { privatereadonlyIStockAnalysisServiceanalysisService; privatereadonlyIOnlineBrokerageServicebrokerageService; publicVerySimpleStockTraderImpl( IStockAnalysisServiceanalysisService, IOnlineBrokerageServicebrokerageService) { this.analysisService = analysisService; this.brokerageService = brokerageService; } publicvoidExecuteTrades() { // ... } } Light Syntax: DI

  17. F# NUnit C# NUnit usingNUnit.Framework; [TestFixture] publicclassMathTest { [Test] publicvoid TwoPlusTwoShouldEqualFour() { Assert.AreEqual(2 + 2, 4); } } moduleMathTest = openNUnit.Framework let [<Test>] ``2 + 2 should equal 4``() = Assert.AreEqual(2 + 2, 4) Unit Testing

  18. BDD

  19. Units of Measure

  20. typeformula = | Negof formula | Expof formula * formula | ArithmeticOpof formula * arithmetic * formula | LogicalOpof formula * logical * formula | NumofUnitValue | Ref ofint * int | Range ofint * int * int * int | Fun of string * formula list Units in Cells

  21. F# 3.0Type Providers

  22. SUMMARY

  23. F# Books

  24. Meet the F#ersTwitter #fsharp

  25. @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

  26. Links Connect @ptrelford phil@trelford.com http://trelford.com/blog • http://fsharp.org • http://fssnip.net • http://tryfsharp.org Q & A

More Related