1 / 48

Reconsidering Strongly Typed Programming in the Information R ich W orld

This talk explores the challenges of information-richness for programming languages and introduces F# and its Type Providers as a solution. Discover how F# can help simplify complex problems and handle information-rich applications.

parkere
Download Presentation

Reconsidering Strongly Typed Programming in the Information R ich W orld

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Reconsidering Strongly Typed Programming in the Information Rich World Don Syme, Principal Researcher, Microsoft Research, UK

  2. F# and Open Source F# 2.0 compiler+library open source drop Apache 2.0 license Runs on Linux, Mac, Windows, Browser

  3. F# for the Browser & Web www.tryfsharp.org (F# Console + Tutorials) pitfw.posterous.com (F# to JS/HTML5, Community) websharper.com (F# to JS/HTML5, Product)

  4. Today’s talk is very simple

  5. Proposition 1The world is information-rich

  6. Proposition 2Modern applications are information-rich

  7. Proposition 3Our languages are information-sparse

  8. Proposition 4This is a problem(especially for strongly typed programming)

  9. With F# we want to help fix this…The mechanism we’re adding to F# is called Type Providers

  10. LINQ= Language Integrated Queries

  11. LINQ + Type Providers= Language Integrated Data and Services

  12. Two aims todayDemonstrate what we’re doing in F# 3.0Explore the ramifications of information-richness for languages, engineering and tooling

  13. But first…What is F#?

  14. F# is… ...a practical,strongly-typed ,functional-first ,supportedlanguagethat allows you to write simplecodeto solve complexproblems.

  15. Simplicity: Functions as Values OO F#    abstract class Command     {       public virtual void Execute(); }     abstract class RoverCommand: Command     { protected Rover Rover { get; private set; } public RoverCommand(MarsRoverrover)       { this.Rover = rover;       } }     class BreakCommand: RoverCommand     {       public BreakCommand(Rover rover) : base(rover)       { }       public override void Execute()       { Rover.Rotate(-5.0);       } } class TurnLeftCommand : RoverCommand   {       public TurnLeftCommand(Rover rover) : base(rover)       {       }       public override void Execute()       { Rover.Rotate(-5.0);       }   } type Command = Command of (Rover -> unit) let BreakCommand= Command(fun rover -> rover.Accelerate(-1.0)) let TurnLeftCommand= Command(fun rover -> rover.Rotate(-5.0<degs>))

  16. Simplicity: Functional Data C# Tuple<U,T> Swap<T,U>(Tuple<T,U> t) { return new Tuple<U,T>(t.Item2, t.Item1) } ReadOnlyCollection<Tuple<T,T,T>> Rotations<T>(Tuple<T,T,T> t) { new ReadOnlyCollection<int> (new Tuple<T,T,T>[] { new Tuple<T,T,T>(t.Item1,t.Item2,t.Item3); new Tuple<T,T,T>(t.Item3,t.Item1,t.Item2); new Tuple<T,T,T>(t.Item2,t.Item3,t.Item1); }); } int Reduce<T>(Func<T,int> f,Tuple<T,T,T> t) { return f(t.Item1) + f(t.Item2) + f (t.Item3); } F# let swap (x, y) = (y, x) let rotations (x, y, z) = [ (x, y, z); (z, x, y); (y, z, x) ] let reduce f (x, y, z) = f x + f y + f z

  17. The Big Trends DATA WEB MULTICORE

  18. Part 2F# 3.0 Information Rich Programming

  19. A ChallengeTask #1: A Chemistry Elements Class LibraryTask #2: Biology…Task #3: Repeat for all Sciences, Businesses, …

  20. Language Integrated Web Data demo

  21. The Data Deluge Organized Data Enormous number of “types” Very interlinked, internally and externally Includes semantic webs, ontologies, web data services, traditional DBs…

  22. A Type Provider is….“A compile-time component that provides a computed space of types and methods on-demand …”“A compiler plug-in…”“An adaptor between data/services and the .NET type system…”

  23. // 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 [<DataContract>] type Result<'TResult> = { [<field: DataMember(Name="code") >] Code:string [<field: DataMember(Name="result") >] Result:'TResult [<field: DataMember(Name="message") >] Message:string } [<DataContract>] type ChemicalElement = { [<field: DataMember(Name="name") >] Name:string [<field: DataMember(Name="boiling_point") >] BoilingPoint:string [<field: DataMember(Name="atomic_mass") >] AtomicMass:string } let Query<'T>(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<Result<'T>>) let result = ser.ReadObject(stream) :?> Result<'T> if result.Code<>"/api/status/ok" then raise (InvalidOperationException(result.Message)) else result.Result let elements = Query<ChemicalElement array>("[{'type':'/chemistry/chemical_element','name':null,'boiling_point':null,'atomic_mass':null}]") elements |> Array.iter(fun element->printfn "%A" element) How would we do this previously?

  24. Note: F# itself still contains no dataOpen architectureYou can write your own type provider

  25. How do we mediate today? Untyped, non-navigable UI designs WCF services WebRequest XmlReader ReadJSON SqlReader ... objects strings bytes Resources program Web services Databases

  26. How do we mediate today? Codegen, Codegen, Codegen!! Does not scale, very clumsy UI designs xaml designer WCF services svcutil.exe types + code Resources resgen.exe program OData datasvcutil.exe Databases edmgen.exe yacg.exe ...

  27. Language Integrated Data Market Directory demo

  28. OData demo

  29. Part 3How F# Type Providers have changed my view of programming languages

  30. Observation 1Huge Information Spaces can be Software Components

  31. Observation 2Type-provider architectures allow languages to avoid l.c.d. effectsRich type systems, importing rich metadata where it exists

  32. Observation 3Languages should also be measured by their effectiveness for working with external information spaces“Programs manipulate in-memory objects”  “Programs manipulate external information spaces”Example: queries, JSON, XML, type providers, async…

  33. Observation 4Programming Type Systemsv.Information Space MetadataExamples: Types, Schema, Constraints, Units of Measure, Security Information, Documentation, Definition Locations, Help , Provenance, Privacy, Ratings, Rankings, Search…

  34. An invitation to partner with Microsoft Research • MSRwant to partner with experts to fuse functional programming + databases + semantic web + … • We’re looking for people who want to be creative in using and extending languages like F# • Help bring data-rich functional programming to '000s of programmers • Experiments can be browser-hosted and delivered, including code editing

  35. SummaryThe world is information richOur programming needs to be information-rich tooInformation-richness changes how we think about programming languages

  36. Thank You!Questions? Contacts: dsyme@microsoft.comwww.fsharp.net, http://blogs.msdn.com/b/fsharpteamTwitter: @dsyme, #fsharp

  37. What Changes? • Traditionally: ├ e :  0 = M1 :  1, … M n :  n • The “initial environment” for a compilation includes a set of providers. Typically each of these are related to one or more external data/service/library stores of the same kind, e.g. 0 = (D0,…,Dn, D  ), …

  38. SQL type SQL = SqlDataConnection<"Server='.\\SQLEXPRESS'.."> Fluent, Typed Access To SQL

  39. SharePoint type EmeaSite = SharePointSite<"http://myemea/"> Fluent, Typed Access To SharePoint Lists

  40. Type Providers: Applications • …web data • …data markets • …network management • …a spreadsheet • …web services • …CRM data • …social data • …SQL data • …XML data • ... strongly typed without explicitcodegen extensible, open

  41. Whitespace Matters letcomputeDerivative f x = letp1 = f (x - 0.05) letp2 = f (x + 0.05) (p2 – p1) / 0.1

  42. Objects + Functional type Vector2D (dx:double, dy:double) = let d2 = dx*dx+dy*dy member v.DX = dx member v.DY = dy member v.Length = sqrt d2 memberv.Scale(k) = Vector2D (dx*k,dy*k)

  43. Example #1 (Power Company) I have written an application to balance the national power generation schedule… for an energy company. ...the calculation engine was written in F#. The use of F# to address the complexity at the heart of this applicationclearly demonstrates a sweet spot for the language … algorithmic analysis of large data sets. Simon Cousins (Eon Powergen)

  44. What Changes? • Type soundness becomes relative to • the stability of schema  type mappings as data sources change • the soundness of the erasure functions of the providers • A program that checks today may not check tomorrow • Depending on the data store, access rights, … • This is true today anyway, because libraries change • It is also true for any external interop based on code generation • Practically speaking, its also true for external interop based on dynamic techniques • Formally, very reminiscent of binary and source compatibility analyses • Memory safety and IL-type safety are unaffected

  45. Ramification 0Software Component v. Information Space Component

  46. Ramification 1Software Engineering v. Information Space EngineeringExamples: Soundness, Stability, Performance, Reliability

  47. Ramification 3Software Component Markets v.Information Space MarketsExample: Windows Azure Marketplace

More Related