Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Presentation to MindTouch engineers: Intro to FSharp

Presentation to MindTouch engineers: Intro to FSharp

A Functional Programming Tour using the F# programming language

César López-Natarén

September 01, 2013
Tweet

More Decks by César López-Natarén

Other Decks in Programming

Transcript

  1. WHAT IS F#? Functional and Object Oriented programming language Full

    support for .NET interoperability Statically typed Support to access other platforms like and through Type Providers Incubated at Microsoft Research, and now a full blown R Matlab open source project
  2. CORRECTNESS We need to make sure our business rules are

    enforced as much as possible by the code Achived through static types, and type inference Concise syntax that avoids boilerplate
  3. CONCISE SYNTAX // Creating values let number = 1 //

    Creating records type User = { Id: int; Name: string } // Type inference let john = { Id = 23; Name = "John D" }
  4. GENERICS & TYPE INFERENCE // Type inference & correctness let

    big a = a > 1000 let bigf a = a > 1000.0 // Lets generalize let bigger a b = a > b let big' a = bigger a 1000 let bigf' a = bigger a 1000.0
  5. FUNCTIONAL PROGRAMMING // Type inference let add a b =

    a + b // Partial application let adder a = add a let add20 = adder 20 // Invocation let twentyOne = add20 1 // Data flow [1 .. 10] |> List.filter (fun n -> n % 2 = 0) |> List.map add20
  6. DISCRIMINATED UNIONS // Exhaustive pattern matching type Option<'a> = |

    Some of 'a | None let printKind something = match something with | Some x -> x.GetType().Name // Null prevention within F# declared types type Person(name : string) = member this.Name = name let printName (p : Person) = printfn "%s" p.Name printName (Person "Haskell Curry") printName null
  7. BENEFITS Being able to change the codebase with agility and

    confidence Generalized programming Static types without being verbose Using functional programming is easier
  8. WTF? “Watch” pane on VS 2012 does not understand how

    to evaluate F# expressions VS 2012’s F# interactive defaults keybindings differ from Bash defaults Xamarin Studio’s F# interactive does not handle multi-line definitions
  9. SKIPPED TOPICS Parallelism constructs Concurrency constructs Lazy sequences Computation Expressions

    Type providers Code Quotations Active Patterns OO and .NET interoperability
  10. RESOURCES FSharp.Org FSharp For Fun And Profit Visual F# FSharp

    Code Snippets Twitter's #fsharp "F# in the Open Source World" by Don Syme
  11. BOOKS by Don Syme et al. by Chris Smith by

    Tomas Petricek with Jon Skeet by Tomas Petricek and Phillip Trelford Expert F# 3.0 Programming F# 3.0 Real World Functional Programming F# Deep Dives