KEMBAR78
Information-rich programming in F# (ML Workshop 2012) | PPTX
Information-rich programming in
                  F#




                  Tomas Petricek, University of Cambridge
                   Don Syme and the F# team, Microsoft


ML Workshop (Copenhagen, 13 September, 2012)
The confusion of languages
The confusion of languages
What is a type provider?
DEMO: Accessing World Bank



Comparing university enrollment rate in
  Czech Republic and OECD countries
Problems with data access

Data is not types with members
 Use dynamic languages?

Need to know names of properties
 Use code generation and static languages?

Enormous scale of data sources
 Types need to be generated “on demand”
Components of a type provider

            Type provider

    IDE                  Compiler
IntelliSense for     Type-Check     Compile using
Provided Types     Provided Types   Type Provider
Research problems
Mapping data sources to types
  What is a type? What is a value?

Types are provided on demand
  Cannot generate all indicator types at once!

Representing data source properties as types
  Physical units, provenance, temporal properties

Adapting to schema change
  Type soundness is relative w.r.t. data source changes
Mapping data source to types



Country




  Indicator     Year
Research problems
Mapping data sources to types
  What is a type? What is a value?

Types are provided on demand
  Cannot generate all indicator types at once!

Representing data source properties as types
  Physical units, provenance, temporal properties

Adapting to schema change
  Type soundness is relative w.r.t. data source changes
Gamma, The Forgotten
Standard typing judgments


Gamma on steroids
            Γ = …,   WB.DataContext
  WB.DataContext = Countries : delay (…)
                               Country list

Reducing delayed context
Research problems
Mapping data sources to types
  What is a type? What is a value?

Types are provided on demand
  Cannot generate all indicator types at once!

Representing data source properties as types
  Physical units, provenance, temporal properties

Adapting to schema change
  Type soundness is relative w.r.t. data source changes
DEMO: XML Type Provider



  Working with XML data and
  adapting to schema change
Related Work

Compile-time meta-programming
 Types generated eagerly, not on demand

Dependently typed languages
 Type-level computation in the IO monad??

Multi-stage computations
 Focus on performance vs. data access
For more information

Upcoming technical report
 Don Syme, et al. Strongly-Typed Language
 Support for an Information-Rich World

Workshop on related topics
 Data Driven Functional Programming
 Workshop, Co-located with POPL 2013
Summary

Mismatch between data and types
 Type providers bridge the gap
 Development-time, compile-time & run-time

Interesting future questions
 Relative type safety and schema change
 Capturing meta-data with types
Research problems
Mapping data sources to types
  What is a type? What is a value?

Types are provided on demand
  Cannot generate all indicator types at once!

Representing data source properties as types
  Physical units, provenance, temporal properties

Adapting to schema change
  Type soundness is relative w.r.t. data source changes
DEMO: FreeBase Type Provider



    Working with chemistry data
       and units of measure
Structure of a Simple Provider
[<TypeProvider>]
type SampleTypeProvider(config: TypeProviderConfig) =
  inherit TypeProviderForNamespaces()

 // Define new type Samples.GeneratedType
 let thisAssembly = Assembly.GetExecutingAssembly()
 let providedType = ProvidedTypeDefinition( ... )
 do
   // Add property 'Hello' that just returns a string
   ProvidedProperty
     ( "Hello", typeof<string>, IsStatic = true,
       GetterCode = fun args -> <@@ Runtime.lookup "Hello" @@>)
   |> providedType.AddMember

   // Register the type with the compiler
   this.AddNamespace(namespaceName, [ providedType ])
Compile-Time vs. Run-time

Type Provider



      Runtime API      Provider

                                     Accesses
                                                 Data
                    Generates                   source
             Uses                    Accesses

                     Provided code
Executable
Compile-Time vs. Run-time

Type Provider



      Runtime API      Provider

                                     Accesses
                                                 Data
                    Generates                   source


                     Provided code
Executable
Queries in F#

Can be turned to quotations
    query { for movie in netflix.Titles do
            where (movie.Name.Contains(search))
            select movie }



Extensible query language
    query { for index in Numbers do
            reverse
            takeWhile index > 10 }

Information-rich programming in F# (ML Workshop 2012)

  • 1.
    Information-rich programming in F# Tomas Petricek, University of Cambridge Don Syme and the F# team, Microsoft ML Workshop (Copenhagen, 13 September, 2012)
  • 2.
  • 3.
  • 4.
    What is atype provider?
  • 5.
    DEMO: Accessing WorldBank Comparing university enrollment rate in Czech Republic and OECD countries
  • 6.
    Problems with dataaccess Data is not types with members Use dynamic languages? Need to know names of properties Use code generation and static languages? Enormous scale of data sources Types need to be generated “on demand”
  • 7.
    Components of atype provider Type provider IDE Compiler IntelliSense for Type-Check Compile using Provided Types Provided Types Type Provider
  • 8.
    Research problems Mapping datasources to types What is a type? What is a value? Types are provided on demand Cannot generate all indicator types at once! Representing data source properties as types Physical units, provenance, temporal properties Adapting to schema change Type soundness is relative w.r.t. data source changes
  • 9.
    Mapping data sourceto types Country Indicator Year
  • 10.
    Research problems Mapping datasources to types What is a type? What is a value? Types are provided on demand Cannot generate all indicator types at once! Representing data source properties as types Physical units, provenance, temporal properties Adapting to schema change Type soundness is relative w.r.t. data source changes
  • 11.
    Gamma, The Forgotten Standardtyping judgments Gamma on steroids Γ = …, WB.DataContext WB.DataContext = Countries : delay (…) Country list Reducing delayed context
  • 12.
    Research problems Mapping datasources to types What is a type? What is a value? Types are provided on demand Cannot generate all indicator types at once! Representing data source properties as types Physical units, provenance, temporal properties Adapting to schema change Type soundness is relative w.r.t. data source changes
  • 13.
    DEMO: XML TypeProvider Working with XML data and adapting to schema change
  • 14.
    Related Work Compile-time meta-programming Types generated eagerly, not on demand Dependently typed languages Type-level computation in the IO monad?? Multi-stage computations Focus on performance vs. data access
  • 15.
    For more information Upcomingtechnical report Don Syme, et al. Strongly-Typed Language Support for an Information-Rich World Workshop on related topics Data Driven Functional Programming Workshop, Co-located with POPL 2013
  • 16.
    Summary Mismatch between dataand types Type providers bridge the gap Development-time, compile-time & run-time Interesting future questions Relative type safety and schema change Capturing meta-data with types
  • 17.
    Research problems Mapping datasources to types What is a type? What is a value? Types are provided on demand Cannot generate all indicator types at once! Representing data source properties as types Physical units, provenance, temporal properties Adapting to schema change Type soundness is relative w.r.t. data source changes
  • 18.
    DEMO: FreeBase TypeProvider Working with chemistry data and units of measure
  • 19.
    Structure of aSimple Provider [<TypeProvider>] type SampleTypeProvider(config: TypeProviderConfig) = inherit TypeProviderForNamespaces() // Define new type Samples.GeneratedType let thisAssembly = Assembly.GetExecutingAssembly() let providedType = ProvidedTypeDefinition( ... ) do // Add property 'Hello' that just returns a string ProvidedProperty ( "Hello", typeof<string>, IsStatic = true, GetterCode = fun args -> <@@ Runtime.lookup "Hello" @@>) |> providedType.AddMember // Register the type with the compiler this.AddNamespace(namespaceName, [ providedType ])
  • 20.
    Compile-Time vs. Run-time TypeProvider Runtime API Provider Accesses Data Generates source Uses Accesses Provided code Executable
  • 21.
    Compile-Time vs. Run-time TypeProvider Runtime API Provider Accesses Data Generates source Provided code Executable
  • 22.
    Queries in F# Canbe turned to quotations query { for movie in netflix.Titles do where (movie.Name.Contains(search)) select movie } Extensible query language query { for index in Numbers do reverse takeWhile index > 10 }