E N D
1. Introducing F# Don Syme
Senior Researcher, Microsoft Research, Cambridge
2. Session Objectives and Agenda A Taste of the F# Language Design
Exploring F# with F# Interactive
Multi-paradigm Programming with F#
3. F#: Combining Paradigms
4. F#: The Combination Counts!
5. F#: Influences
6. The Path to Mastering F#
7. Quick Overview
8. Quick Tour
9. Quick Overview: Types
10. Orthogonal & Unified Constructs
Let let simplify your life
11. F# - Control Flow
12. Demo: Lets WebCrawl
13. F# - Functional let f x = x+1
let pair x = (x,x)
let fst (x,y) = x
let data = (Some [1;2;3], Some [4;5;6])
match data with
| Some(nums1), Some(nums2) -> nums1 @ nums2
| None, Some(nums) -> nums
| Some(nums), None -> nums
| None, None -> failwith "missing!"
14. F#: Patterns
15. Patterns are Everywhere
16. Quick Overview: Functions
17. Orthogonal & Unified Constructs Functions: like delegates + unified and simple
18. Immutability the norm
19. F# - Functional List.map Seq.fold
Array.filter Lazy.force Set.union
Map LazyList Events Async...
[ 0..1000 ]
[ for x in 0..10 -> (x, x * x) ]
[| for x in 0..10 -> (x, x * x) |]
seq { for x in 0..10 -> (x, x * x) }
20. F# - Sequences open System.IO
let rec allFiles(dir) =
seq
{ for file in Directory.GetFiles(dir) do
yield file
for sub in Directory.GetDirectories(dir) do
yield! allFiles(sub) }
allFiles(@"C:\WINDOWS") |> Seq.take 100 |> show
21. //F#
#light
open System
let a = 2
Console.WriteLine(a) Dynamic? But why does F# omit any type information? Is it not type safe? Is it coercive maybe? Or weakly typed? Maybe this is one of those dynamic languages I read about at 37 signals?But why does F# omit any type information? Is it not type safe? Is it coercive maybe? Or weakly typed? Maybe this is one of those dynamic languages I read about at 37 signals?
22. But it has some features to make this a little more comfortable. Well see a bit of that later.But it has some features to make this a little more comfortable. Well see a bit of that later.
23. Constraints and Variables
24. Experimenting with Sequences and Functions
25. F# - Imperative + Functional open System.Collections.Generic
let dict = new Dictionary<int,string>(1000)
dict.[17] <- "Seventeen"
dict.[1000] <- "One Grand"
for (KeyValue(k,v)) in dict do
printfn "key = %d, value = %s" k v
26. F# - Control Flow
27. F# - Imperative + Functional
open System.IO
open System.Collections.Generic
let readAllLines(file) =
use inp = File.OpenText file
let res = new List<_>()
while not(inp.EndOfStream) do
res.Add(inp.ReadLine())
res.ToArray()
28. F# - Imperative + Functional
open System.IO
let allLines =
seq { use inp = File.OpenText "test.txt"
while not(inp.EndOfStream) do
yield (inp.ReadLine()) }
allLines
|> Seq.truncate 1000
|> Seq.map (fun s -> uppercase s,s)
|> Seq.to_array
29. Seamlessly combines procedural functional and object oriented styles (lets leave language oriented for another day)Seamlessly combines procedural functional and object oriented styles (lets leave language oriented for another day)
30. Objects
31. F# - Objects + Functional type Vector2D(dx:double,dy:double) =
member v.DX = dx
member v.DY = dy
member v.Length = sqrt(dx*dx+dy*dy)
member v.Scale(k) = Vector2D(dx*k,dy*k)
32. F# - Objects + Functional type Vector2D(dx:double,dy:double) =
let norm2 = dx*dx+dy*dy
member v.DX = dx
member v.DY = dy
member v.Length = sqrt(norm2)
member v.Norm2 = norm2
33. F# - Objects + Functional type MutableVector2D(dx:double,dy:double) =
let mutable currDX = dx
let mutable currDX = dy
member v.DX = currDX
member v.DY = currDY
member v.Move(x,y) =
currDX <- currDX+x
currDY <- currDY+y
34. Quick Overview
35. F# - Language Oriented type PropLogic =
| And of PropLogic * PropLogic
| Not of PropLogic
| True
let rec Eval(prop) =
match prop with
| And(a,b) -> Eval(a) && Eval(b)
| Not(a) -> not (Eval(a))
| True -> true
36. F# - What is it for?
37. F# - What is it For? F# is a General Purpose language
F# is also A Bridge Language
A Language Both Researchers and Developers Can Speak
Some important domains
Scientific data analysis
Data mining
Domain-specific modeling
Financial modeling and analysis
38. The adCenter Problem Cash-cow of Search
Selling web space at www.live.com and www.msn.com.
Paid Search (prices by auctions)
The internal competition focuses on Paid Search.
39. The Scale of Things Weeks of data in training:
7,000,000,000 impressions, 6TB data
2 weeks of CPU time during training:
2 wks × 7 days × 86,400 sec/day =
1,209,600 seconds
Learning algorithm speed requirement:
5,787 impression updates / sec
172.8 µs per impression update
40. F# and adCenter 4 week project, 4 machine learning experts
100million probabilistic variables
Processes 6TB of training data
Real time processing
41. The Teams Summary F# was absolutely integral to our success
We delivered a robust, high-performance solution on-time.
We couldnt have achieved this with any other tool given the constraints of the task
F# programming is fun I feel like I learn more about programming every day
42. APG Machine Learning Observations
Quick Coding
Agile Coding
Scripting
Performance
Memory-Faithful
Succinct
Symbolic
.NET Integration
43. F# for Bioinformatics "Rain" Genome Assembly Viewer
Implemented by Darren Platt: Head of Bioinformatics, DOE JGI
They sequence 20% of world's DNA
Co-author on Neanderthal DNA sequencing paper.
Experienced, trained programmer
F# /.NET/C++ v. Perl/C++ v. Python/C++
44. F# - Concurrent/Reactive/Parallel
Concurrent: Multiple threads of execution
Parallel: These execute simultaneously
Asynchronous: Computations complete "later"
Reactive: Waiting and responding is normal
45. Taming Asynchronous I/O
46. Books about F#
47. 8 Ways to Learn FSI.exe
Samples Included
Go to definition
Lutz Reflector
48. A Thank You to French ResearchF# is inspired by Ocaml and partially compatible with it. Thank you INRIA!The design of F# draws on years of research in this class of language by INRIA, as well as other academic institutes across the world
50.
La référence technique
pour les IT Pros :
technet.microsoft.com
51. Computing with Functions
open System.IO
Remap : src:Rectangle * dest:Rectangle
-> (Rectangle -> Rectangle)
52. F#: Patterns
53. TrueSkill extensions developed and deployed
Partial updates: Progressive Hill-climbing experience
Skill transformation: Linking skill- and experience-based ranking (monotonically increasing smooth splines)
Public beta-test 2007
Simulation of level distribution (2006) matched almost exactly findings during the beta test (2007).
From a consumer entertainment standpoint, comparable to Spiderman 3 or Harry Potter (Shane Kim).
Applied Games team will be mentioned in game credits TrueSkill in Halo 3
54. Computing with Functions