Upload
talbott-crowell
View
5.584
Download
1
Tags:
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
Introduction to F# 3.0
Talbott Crowell, MVP
@talbott
#BOSCCBoston Code Camp
October 20, 2012
What is F#Statically typed, open
sourcefunctional programming
language that uses type inferencing
Unique features:Units of MeasureType Providers
Static versus Dynamic
F# is statically typed like:
C++, Objective-C, Java, Scala
Compared to dynamically typed languages:
Python, JavaScript, Erlang, MATLAB
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
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
Type Inferencing
let x = 5let y = "hello"let z = new Form()let distance = 26.21875<mile>let f x = x + x
Immutable by default
let x = 5let mutable y = 7y <- 8
let z = new Form()z.Show()z.Text <- “Hello”
Array, List, and Seq
Arrays are mutable
Lists are not
Seq (sequences) only store one value at a time (lazy)
Array, List, and Seq
let set1 = [|1..10|]let set2 = [1..10]let set3 = seq { 1..10 }
set1.[0] <- 999 //mutable
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.
Units of Measure
[<Measure>] type mile[<Measure>] type km
let distance1 = 4.0<mile>let distance2 = 3.0<km>//compile errorlet total = distance1 + distance2
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
Type ProvidersF# 3.0 introduces Type Providers
Data rich programming for the Big Data Era
Enables massive schemas with strict typing
Examples of Type Providers
SQL Data ConnectionOData Service Provider (Netflix)
FreebaseHadoop
RWMI
RegEx
Type Provider Demo
TryFsharp.org
FPish.net
Other Resourceshttp://stackoverflow.com/questions/tagged/f%23
http://fsharpsamples.codeplex.com/
http://fsharp.net
Questions?
Thank You
Follow me on Twitter
@Talbott