Presentation is loading. Please wait.

Presentation is loading. Please wait.

F# 3.0: Data, Services, Web, Cloud, at Your Fingertips Dustin Campbell Senior Program Manager Microsoft Corporation DEV338.

Similar presentations


Presentation on theme: "F# 3.0: Data, Services, Web, Cloud, at Your Fingertips Dustin Campbell Senior Program Manager Microsoft Corporation DEV338."— Presentation transcript:

1 F# 3.0: Data, Services, Web, Cloud, at Your Fingertips Dustin Campbell Senior Program Manager Microsoft Corporation DEV338

2

3 F# is a practical, functional-first language that lets you write simple code to solve complex problems

4

5

6 Simplicity

7 abstract class RoverCommand { protected Rover Rover { get; private set; } public RoverCommand(Rover rover) { this.Rover = rover; } abstract void Execute(); } class BrakeCommand : RoverCommand { public BrakeCommand(Rover rover) : base(rover) { } public override void Execute() { Rover.Accelerate(-1.0); } class TurnLeftCommand : RoverCommand { public TurnLeftCommand(Rover rover) : base(rover) { } public override void Execute() { Rover.Rotate(-5.0); } type RoverCommand = Command of (Rover -> unit) let BrakeCommand = Command(fun rover -> rover.Accelerate(-1.0 )) let TurnLeftCommand = Command(fun rover -> rover.Rotate(-5.0 )) F# C#

8 let swap (x, y) = (y, x) let rotations (x, y, z) = seq [ (x, y, z) (z, x, y) (y, z, x) ] let reduce f (x, y, z) = f x + f y + f z Tuple Swap (Tuple t) { return Tuple.Create(t.Item2, t.Item1) } IEnumerable > Rotations (Tuple t) { yield return Tuple.Create(t.Item1, t.Item2, t.Item3); yield return Tuple.Create(t.Item3, t.Item1, t.Item2); yield return Tuple.Create(t.Item2, t.Item3, t.Item1); } int Reduce (Func f, Tuple t) { return f(t.Item1) + f(t.Item2) + f (t.Item3); } F# C#

9 F# is declarative www.flickr.com/photos/bigbirdz www.flickr.com/photos/digitalcolony www.flickr.com/photos/richardaustin www.flickr.com/photos/bigiain

10 Demo Simplicity – an F# Primer

11 What about real-world tasks?

12 F# 3.0 Information Rich Programming

13 Two propositions

14 Proposition 1 We live in an information society

15 Proposition 2 Our languages are information sparse

16 This is a problem

17

18

19 source: blog.programmableweb.com

20 F# Type Providers: IntelliSense for data

21 Demo Freebase

22 http://wiki.freebase.com/wiki/Main_Page

23 Demo Freebase

24 // Freebase.fsx // Example of reading from freebase.com in F# // by Jomo Fisher #r "System.Runtime.Serialization" #r "System.ServiceModel.Web" #r "System.Web" #r "System.Xml" open System open System.IO open System.Net open System.Text open System.Web open System.Security.Authentication open System.Runtime.Serialization [ ] type Result = { [ ] Code:string [ ] Result:'TResult [ ] Message:string } [ ] type ChemicalElement = { [ ] Name:string [ ] BoilingPoint:string [ ] AtomicMass:string } // Freebase.fsx // Example of reading from freebase.com in F# // by Jomo Fisher #r "System.Runtime.Serialization" #r "System.ServiceModel.Web" #r "System.Web" #r "System.Xml" open System open System.IO open System.Net open System.Text open System.Web open System.Security.Authentication open System.Runtime.Serialization [ ] type Result = { [ ] Code:string [ ] Result:'TResult [ ] Message:string } [ ] type ChemicalElement = { [ ] Name:string [ ] BoilingPoint:string [ ] AtomicMass:string } let Query (query:string) : 'T = let query = query.Replace("'","\"") let queryUrl = sprintf "http://api.freebase.com/api/service/mqlread?query=%s" "{\"query\":"+query+"}" let request : HttpWebRequest = downcast WebRequest.Create(queryUrl) request.Method <- "GET" request.ContentType <- "application/x-www-form-urlencoded" let response = request.GetResponse() let result = try use reader = new StreamReader(response.GetResponseStream()) reader.ReadToEnd(); finally response.Close() let data = Encoding.Unicode.GetBytes(result); let stream = new MemoryStream() stream.Write(data, 0, data.Length); stream.Position <- 0L let ser = Json.DataContractJsonSerializer(typeof >) let result = ser.ReadObject(stream) :?> Result if result.Code <> "/api/status/ok" then raise (InvalidOperationException(result.Message)) else result.Result let elements = Query ("[{'type':'/chemistry/chemical_element','name':null,'boiling_point':null, 'atomic_mass':null}]") elements |> Array.iter(fun element -> printfn "%A" element) let Query (query:string) : 'T = let query = query.Replace("'","\"") let queryUrl = sprintf "http://api.freebase.com/api/service/mqlread?query=%s" "{\"query\":"+query+"}" let request : HttpWebRequest = downcast WebRequest.Create(queryUrl) request.Method <- "GET" request.ContentType <- "application/x-www-form-urlencoded" let response = request.GetResponse() let result = try use reader = new StreamReader(response.GetResponseStream()) reader.ReadToEnd(); finally response.Close() let data = Encoding.Unicode.GetBytes(result); let stream = new MemoryStream() stream.Write(data, 0, data.Length); stream.Position <- 0L let ser = Json.DataContractJsonSerializer(typeof >) let result = ser.ReadObject(stream) :?> Result if result.Code <> "/api/status/ok" then raise (InvalidOperationException(result.Message)) else result.Result let elements = Query ("[{'type':'/chemistry/chemical_element','name':null,'boiling_point':null, 'atomic_mass':null}]") elements |> Array.iter(fun element -> printfn "%A" element)

25

26 Demo Web service and multiple data sources

27

28 Demo Where should I live?

29

30 Tools matter!

31

32 Visual Studio Home Page :: http://www.microsoft.com/visualstudio/en-ushttp://www.microsoft.com/visualstudio/en-us Jason Zander’s Blog :: http://blogs.msdn.com/b/jasonz/http://blogs.msdn.com/b/jasonz/ Facebook :: http://www.facebook.com/visualstudiohttp://www.facebook.com/visualstudio Twitter :: http://twitter.com/#!/visualstudiohttp://twitter.com/#!/visualstudio Somasegar’s Blog :: http://blogs.msdn.com/b/somasegar/http://blogs.msdn.com/b/somasegar/

33 Connect. Share. Discuss. http://europe.msteched.com Learning Microsoft Certification & Training Resources www.microsoft.com/learning TechNet Resources for IT Professionals http://microsoft.com/technet Resources for Developers http://microsoft.com/msdn

34 Evaluations http://europe.msteched.com/sessions Submit your evals online

35


Download ppt "F# 3.0: Data, Services, Web, Cloud, at Your Fingertips Dustin Campbell Senior Program Manager Microsoft Corporation DEV338."

Similar presentations


Ads by Google