![Page 1: Information-rich programming in F# (ML Workshop 2012)](https://reader036.vdocuments.net/reader036/viewer/2022062419/557cf492d8b42a071b8b4727/html5/thumbnails/1.jpg)
Information-rich programming in F#
Tomas Petricek, University of Cambridge
Don Syme and the F# team, Microsoft
ML Workshop (Copenhagen, 13 September, 2012)
![Page 2: Information-rich programming in F# (ML Workshop 2012)](https://reader036.vdocuments.net/reader036/viewer/2022062419/557cf492d8b42a071b8b4727/html5/thumbnails/2.jpg)
The confusion of languages
![Page 3: Information-rich programming in F# (ML Workshop 2012)](https://reader036.vdocuments.net/reader036/viewer/2022062419/557cf492d8b42a071b8b4727/html5/thumbnails/3.jpg)
The confusion of languages
![Page 4: Information-rich programming in F# (ML Workshop 2012)](https://reader036.vdocuments.net/reader036/viewer/2022062419/557cf492d8b42a071b8b4727/html5/thumbnails/4.jpg)
What is a type provider?
![Page 5: Information-rich programming in F# (ML Workshop 2012)](https://reader036.vdocuments.net/reader036/viewer/2022062419/557cf492d8b42a071b8b4727/html5/thumbnails/5.jpg)
DEMO: Accessing World Bank
Comparing university enrollment rate in Czech Republic and OECD
countries
![Page 6: Information-rich programming in F# (ML Workshop 2012)](https://reader036.vdocuments.net/reader036/viewer/2022062419/557cf492d8b42a071b8b4727/html5/thumbnails/6.jpg)
Problems with data access
Data is not types with membersUse dynamic languages?
Need to know names of propertiesUse code generation and static languages?
Enormous scale of data sourcesTypes need to be generated “on demand”
![Page 7: Information-rich programming in F# (ML Workshop 2012)](https://reader036.vdocuments.net/reader036/viewer/2022062419/557cf492d8b42a071b8b4727/html5/thumbnails/7.jpg)
Components of a type provider
Type provider
IDEIntelliSense for Provided
Types
CompilerType-Check
Provided Types
Compile using Type Provider
![Page 8: Information-rich programming in F# (ML Workshop 2012)](https://reader036.vdocuments.net/reader036/viewer/2022062419/557cf492d8b42a071b8b4727/html5/thumbnails/8.jpg)
Research problems
Mapping data sources to typesWhat is a type? What is a value?
Types are provided on demandCannot generate all indicator types at once!
Representing data source properties as typesPhysical units, provenance, temporal properties
Adapting to schema changeType soundness is relative w.r.t. data source changes
![Page 9: Information-rich programming in F# (ML Workshop 2012)](https://reader036.vdocuments.net/reader036/viewer/2022062419/557cf492d8b42a071b8b4727/html5/thumbnails/9.jpg)
Mapping data source to types
Country
YearIndicator
![Page 10: Information-rich programming in F# (ML Workshop 2012)](https://reader036.vdocuments.net/reader036/viewer/2022062419/557cf492d8b42a071b8b4727/html5/thumbnails/10.jpg)
Research problems
Mapping data sources to typesWhat is a type? What is a value?
Types are provided on demandCannot generate all indicator types at once!
Representing data source properties as typesPhysical units, provenance, temporal properties
Adapting to schema changeType soundness is relative w.r.t. data source changes
![Page 11: Information-rich programming in F# (ML Workshop 2012)](https://reader036.vdocuments.net/reader036/viewer/2022062419/557cf492d8b42a071b8b4727/html5/thumbnails/11.jpg)
WB.DataContext = Countries : delay (…)WB.DataContext = Countries : Country list
Gamma, The Forgotten
Standard typing judgments
Gamma on steroids
Reducing delayed context
’
Γ⊢𝑒 :𝜏
Γ = …, WB.DataContext
![Page 12: Information-rich programming in F# (ML Workshop 2012)](https://reader036.vdocuments.net/reader036/viewer/2022062419/557cf492d8b42a071b8b4727/html5/thumbnails/12.jpg)
Research problems
Mapping data sources to typesWhat is a type? What is a value?
Types are provided on demandCannot generate all indicator types at once!
Representing data source properties as typesPhysical units, provenance, temporal properties
Adapting to schema changeType soundness is relative w.r.t. data source changes
![Page 13: Information-rich programming in F# (ML Workshop 2012)](https://reader036.vdocuments.net/reader036/viewer/2022062419/557cf492d8b42a071b8b4727/html5/thumbnails/13.jpg)
DEMO: XML Type Provider
Working with XML data and adapting to schema change
![Page 14: Information-rich programming in F# (ML Workshop 2012)](https://reader036.vdocuments.net/reader036/viewer/2022062419/557cf492d8b42a071b8b4727/html5/thumbnails/14.jpg)
Related Work
Compile-time meta-programmingTypes generated eagerly, not on demand
Dependently typed languagesType-level computation in the IO monad??
Multi-stage computationsFocus on performance vs. data access
![Page 15: Information-rich programming in F# (ML Workshop 2012)](https://reader036.vdocuments.net/reader036/viewer/2022062419/557cf492d8b42a071b8b4727/html5/thumbnails/15.jpg)
For more information
Upcoming technical reportDon Syme, et al. Strongly-Typed Language Support for an Information-Rich World
Workshop on related topicsData Driven Functional Programming Workshop, Co-located with POPL 2013
![Page 16: Information-rich programming in F# (ML Workshop 2012)](https://reader036.vdocuments.net/reader036/viewer/2022062419/557cf492d8b42a071b8b4727/html5/thumbnails/16.jpg)
Summary
Mismatch between data and typesType providers bridge the gapDevelopment-time, compile-time & run-time
Interesting future questionsRelative type safety and schema changeCapturing meta-data with types
![Page 17: Information-rich programming in F# (ML Workshop 2012)](https://reader036.vdocuments.net/reader036/viewer/2022062419/557cf492d8b42a071b8b4727/html5/thumbnails/17.jpg)
Research problems
Mapping data sources to typesWhat is a type? What is a value?
Types are provided on demandCannot generate all indicator types at once!
Representing data source properties as typesPhysical units, provenance, temporal properties
Adapting to schema changeType soundness is relative w.r.t. data source changes
![Page 18: Information-rich programming in F# (ML Workshop 2012)](https://reader036.vdocuments.net/reader036/viewer/2022062419/557cf492d8b42a071b8b4727/html5/thumbnails/18.jpg)
DEMO: FreeBase Type Provider
Working with chemistry data and units of measure
![Page 19: Information-rich programming in F# (ML Workshop 2012)](https://reader036.vdocuments.net/reader036/viewer/2022062419/557cf492d8b42a071b8b4727/html5/thumbnails/19.jpg)
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 ])
![Page 20: Information-rich programming in F# (ML Workshop 2012)](https://reader036.vdocuments.net/reader036/viewer/2022062419/557cf492d8b42a071b8b4727/html5/thumbnails/20.jpg)
Compile-Time vs. Run-time
Type Provider
Data source
Executable
Runtime API
Provided code
Generates
Uses Accesses
Accesses
Provider
![Page 21: Information-rich programming in F# (ML Workshop 2012)](https://reader036.vdocuments.net/reader036/viewer/2022062419/557cf492d8b42a071b8b4727/html5/thumbnails/21.jpg)
Compile-Time vs. Run-time
Type Provider
Executable
Generates
Accesses
ProviderRuntime API
Provided code
Data source
![Page 22: Information-rich programming in F# (ML Workshop 2012)](https://reader036.vdocuments.net/reader036/viewer/2022062419/557cf492d8b42a071b8b4727/html5/thumbnails/22.jpg)
Queries in F#
Can be turned to quotations
Extensible query language
query { for movie in netflix.Titles do where (movie.Name.Contains(search)) select movie }
query { for index in Numbers do reverse takeWhile index > 10 }