fsharp shdh 40 lightning talk

9
Some F# Highlights Matt Harrington [email protected]

Upload: mbhwork

Post on 18-Dec-2014

521 views

Category:

Documents


0 download

DESCRIPTION

A 5 minute lightning talk given at SHDH 40 on F#.

TRANSCRIPT

Page 1: Fsharp shdh 40 lightning talk

Some F# Highlights

Matt [email protected]

Page 2: Fsharp shdh 40 lightning talk

Robin MilnerUniversity of EdinburghML – 1970s

Xavier Leroy, et al.INRIA, FranceOcaml - 1996

Don SymeMSR CambridgeF# - 2002

Page 3: Fsharp shdh 40 lightning talk
Page 4: Fsharp shdh 40 lightning talk

FP• First class functions• Immutability• Recursion• Type inference• Pattern matching• Lists, sequences,

tuples, records, discriminated unions

• Option type

• Monads• Asynchronous

programming• Pipeline operator |>• Currying• Continuations• Memoization

Page 5: Fsharp shdh 40 lightning talk

OO

• Classes• Inheritance• Interfaces• Structs• Properties• Delegates• Enums• Mutability

Page 6: Fsharp shdh 40 lightning talk

Tail Call Optimization.method public static int32 g(int32 x) cil managed{ .maxstack 5 L_0000: nop L_0001: ldarg.0 L_0002: ldc.i4.0 L_0003: ble.s L_0007 L_0005: br.s L_0009 L_0007: br.s L_0019 L_0009: newobj instance void Program/g@9::.ctor() L_000e: ldarg.0 L_000f: ldc.i4.1 L_0010: sub L_0011: tail L_0013: call int32 Program::f(class [FSharp.Core]Microsoft.<snip>) L_0018: ret L_0019: ldarg.0 L_001a: ret }

Page 7: Fsharp shdh 40 lightning talk

Units of Measure

[<Measure>]type kilogram

let bowlingBall = 7.26<kilogram>

let force (mass: float<kilogram>) = mass * 9.8

Page 8: Fsharp shdh 40 lightning talk

Code from "Juliet" on StackOverflow.

Euler Problem #7let isPrime num = let upperDivisor = int32(sqrt(float num)) match num with | 0 | 1 -> false | 2 -> true | n -> seq { 2 .. upperDivisor } |>

Seq.forall (fun x -> num % x <> 0) let primes = Seq.initInfinite id |> Seq.filter isPrime let nthPrime n = Seq.nth n primes printfn "The 10001st prime number is %i."

(nthPrime 10001)

Page 9: Fsharp shdh 40 lightning talk

More…

• Matt Harrington: [email protected]• SFsharp.org• Luca Bolognese’s video (see links on

SFsharp.org)• Programming F# by Chris Smith