20
Introduction to F# 3.0 Talbott Crowell, MVP @talbott #BOSCC Boston Code Camp October 20, 2012

Introduction to F# 3.0

Embed Size (px)

DESCRIPTION

Talbott Crowell introduces F# 3.0 including function programming basics, units of measure, and the new F# 3.0 feature called Type Providers for analyzing Big Data

Citation preview

Page 1: Introduction to F# 3.0

Introduction to F# 3.0

Talbott Crowell, MVP

@talbott

#BOSCCBoston Code Camp

October 20, 2012

Page 2: Introduction to F# 3.0

What is F#Statically typed, open

sourcefunctional programming

language that uses type inferencing

Unique features:Units of MeasureType Providers

Page 3: Introduction to F# 3.0

Static versus Dynamic

F# is statically typed like:

C++, Objective-C, Java, Scala

Compared to dynamically typed languages:

Python, JavaScript, Erlang, MATLAB

Page 4: Introduction to F# 3.0

Open SourceApache 2.0 licenseFree IDE on Windows from MicrosoftFree IDE on Mac (MonoDevelop)

http://blogs.msdn.com/b/fsharpteam/archive/2012/09/24/announcing-the-f-3-0-open-source-code-drop.aspx

Page 5: Introduction to F# 3.0

Functional Programming (FP)

Examples of FP languagesErlang, Haskell, Clojure and Scala (JVM)

Functions are first class citizenslike variables in imperative languages

Higher-order functionsfunctions a parameters or return values

Page 6: Introduction to F# 3.0

Type Inferencing

let x = 5let y = "hello"let z = new Form()let distance = 26.21875<mile>let f x = x + x

Page 7: Introduction to F# 3.0

Immutable by default

let x = 5let mutable y = 7y <- 8

let z = new Form()z.Show()z.Text <- “Hello”

Page 8: Introduction to F# 3.0

Array, List, and Seq

Arrays are mutable

Lists are not

Seq (sequences) only store one value at a time (lazy)

Page 9: Introduction to F# 3.0

Array, List, and Seq

let set1 = [|1..10|]let set2 = [1..10]let set3 = seq { 1..10 }

set1.[0] <- 999 //mutable

Page 10: Introduction to F# 3.0

Units of MeasureFloating point and signed integer values in F# can have associated units of measure, which are typically used to indicate length, volume, mass, and so on.

By using quantities with units, you enable the compiler to verify that arithmetic relationships have the correct units, which helps prevent programming errors.

Page 11: Introduction to F# 3.0

Units of Measure

[<Measure>] type mile[<Measure>] type km

let distance1 = 4.0<mile>let distance2 = 3.0<km>//compile errorlet total = distance1 + distance2

Page 12: Introduction to F# 3.0

Units of Measure

[<Measure>] type mile[<Measure>] type kmlet convert_mile2km (a : float<mile>) = a / 0.621371<mile/km>

let distance1 = 4.0<mile>let distance1a = convert_mile2km distance1let distance2 = 3.0<km>

let total = distance1a + distance2

Page 13: Introduction to F# 3.0

Type ProvidersF# 3.0 introduces Type Providers

Data rich programming for the Big Data Era

Enables massive schemas with strict typing

Page 14: Introduction to F# 3.0

Examples of Type Providers

SQL Data ConnectionOData Service Provider (Netflix)

FreebaseHadoop

RWMI

RegEx

Page 15: Introduction to F# 3.0

Type Provider Demo

Page 16: Introduction to F# 3.0

TryFsharp.org

Page 17: Introduction to F# 3.0

FPish.net

Page 19: Introduction to F# 3.0

Questions?

Page 20: Introduction to F# 3.0

Thank You

Follow me on Twitter

@Talbott