SlideShare une entreprise Scribd logo
1  sur  21
F# Type Providers in Depth

          Tomas Petricek
 @tomaspetricek | http://tomasp.net
F# 3.0 in Visual Studio 11
The Problem
   Meta-data                    <s:complexType name="Session">
                                <s:sequence>
                                  <s:element minOccurs="0" maxOccurs="1"

  information                                name="CustomerID" type="s:string" />
                                  <s:element minOccurs="0" maxOccurs="1"
                                             name="CustomerName" type="s:string" />

       ≠                          <s:element minOccurs="0" maxOccurs="1"
                                             name="BranchNumber" type="s:string" />
                                  <s:element minOccurs="0" maxOccurs="1"

    F# type                                  name="SessionKey" type="s:string" />
                                  <s:element minOccurs="0" maxOccurs="1"
                                             name="ChosenDeliverySlotInfo"
  declaration                                type="s:string" />
                                  <s:element minOccurs="0" maxOccurs="1"
                                             name="CustomerMessageOfTheDay"
                                             type="s:string" />
type Session =                    <s:element minOccurs="0" maxOccurs="1"
                                             name="CustomerForename"
  { CustomerID : int                         type="s:string" />
    CustomerName : string       </s:sequence>
                                </s:complexType>
    BranchNumber : int
    SessionKey : string
    ChosenDeliverySlotInfo : string
    CustomerMessageOfTheDay : string
    CustomerForName : string }
The Problem
Levels of Data Access

Expression Scale       Program Scale
  Dynamic typing        Code generation


            Internet Scale
             Type providers
Type providers change
 how you think about
   programming!
DEMO: WORLD BANK
What is a Type Provider?
How are Type Providers used?


              Type provider

    IDE                    Compiler
 IntelliSense for     Type-Check     Compile using
Generated Types     Imported Types   Type Provider
Type Providers for .NET

Hiding code generation
 Web Services (WSDL)
 SQL databases (LINQ to Entities)

Erasing provided types
 REST services (World Bank)
 Schematized web (Freebase)
DEMO: WSDL, SQL, ODATA
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 }
Implementing Type Providers

 public interface ITypeProvider
 {
    Type[] GetTypes();

     Expression GetInvokerExpression
        ( MethodBase method,
          ParameterExpression[] params );

     event EventHandler Invalidate;
 }
Design Considerations

Choosing the right view
  Provide the right projection
  Inferring structure from data

Schema structure
  Refreshing the schema
  Caching of online schema
DEMO: XML TYPE PROVIDER
Summary

The ease of dynamic languages
  Generate types from schema
  No actual types are needed

With the static typing benefits
  Checked at compile-time
  Full IntelliSense support
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
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 ])

Contenu connexe

Tendances

Language processor implementation using python
Language processor implementation using pythonLanguage processor implementation using python
Language processor implementation using python
Viktor Pyskunov
 
Internationlization
InternationlizationInternationlization
Internationlization
Tuan Ngo
 
C++ OOP Implementation
C++ OOP ImplementationC++ OOP Implementation
C++ OOP Implementation
Fridz Felisco
 

Tendances (20)

Object oriented programming c++
Object oriented programming c++Object oriented programming c++
Object oriented programming c++
 
c# usage,applications and advantages
c# usage,applications and advantages c# usage,applications and advantages
c# usage,applications and advantages
 
Protocol buffers
Protocol buffersProtocol buffers
Protocol buffers
 
Language processor implementation using python
Language processor implementation using pythonLanguage processor implementation using python
Language processor implementation using python
 
Object Oriented Programming With Real-World Scenario
Object Oriented Programming With Real-World ScenarioObject Oriented Programming With Real-World Scenario
Object Oriented Programming With Real-World Scenario
 
Ppt of c++ vs c#
Ppt of c++ vs c#Ppt of c++ vs c#
Ppt of c++ vs c#
 
Introduction to perl_ a scripting language
Introduction to perl_ a scripting languageIntroduction to perl_ a scripting language
Introduction to perl_ a scripting language
 
Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...
Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...
Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...
 
Internationlization
InternationlizationInternationlization
Internationlization
 
How F# Learned to Stop Worrying and Love the Data
How F# Learned to Stop Worrying and Love the DataHow F# Learned to Stop Worrying and Love the Data
How F# Learned to Stop Worrying and Love the Data
 
Controlled Natural Language rendering of Copyright Ontology licenses
Controlled Natural Language rendering of Copyright Ontology licensesControlled Natural Language rendering of Copyright Ontology licenses
Controlled Natural Language rendering of Copyright Ontology licenses
 
Dart programming language
Dart programming languageDart programming language
Dart programming language
 
Introduction to c++ ppt 1
Introduction to c++ ppt 1Introduction to c++ ppt 1
Introduction to c++ ppt 1
 
pebble - Building apps on pebble
pebble - Building apps on pebblepebble - Building apps on pebble
pebble - Building apps on pebble
 
2 expressions (ppt-2) in C++
2 expressions (ppt-2) in C++2 expressions (ppt-2) in C++
2 expressions (ppt-2) in C++
 
C by balaguruswami - e.balagurusamy
C   by balaguruswami - e.balagurusamyC   by balaguruswami - e.balagurusamy
C by balaguruswami - e.balagurusamy
 
C++ OOP Implementation
C++ OOP ImplementationC++ OOP Implementation
C++ OOP Implementation
 
Andy On Closures
Andy On ClosuresAndy On Closures
Andy On Closures
 
Dart workshop
Dart workshopDart workshop
Dart workshop
 
Linq
LinqLinq
Linq
 

Similaire à F# Type Providers in Depth

Developer power tools
Developer power toolsDeveloper power tools
Developer power tools
Nick Harrison
 
540slidesofnodejsbackendhopeitworkforu.pdf
540slidesofnodejsbackendhopeitworkforu.pdf540slidesofnodejsbackendhopeitworkforu.pdf
540slidesofnodejsbackendhopeitworkforu.pdf
hamzadamani7
 
Introducing the WSO2 Complex Event Processor
Introducing the WSO2 Complex Event ProcessorIntroducing the WSO2 Complex Event Processor
Introducing the WSO2 Complex Event Processor
WSO2
 
Complex Event Processor 3.0.0 - An overview of upcoming features
Complex Event Processor 3.0.0 - An overview of upcoming features Complex Event Processor 3.0.0 - An overview of upcoming features
Complex Event Processor 3.0.0 - An overview of upcoming features
WSO2
 
Lets have some fun with twilio open tok
Lets have some fun with   twilio open tokLets have some fun with   twilio open tok
Lets have some fun with twilio open tok
mirahman
 
Understanding Reflection
Understanding ReflectionUnderstanding Reflection
Understanding Reflection
Tamir Khason
 
PCI Security Requirements - secure coding
PCI Security Requirements - secure codingPCI Security Requirements - secure coding
PCI Security Requirements - secure coding
Haitham Raik
 

Similaire à F# Type Providers in Depth (20)

Developer power tools
Developer power toolsDeveloper power tools
Developer power tools
 
ADO.NET Entity Framework by Jose A. Blakeley and Michael Pizzo
ADO.NET Entity Framework by Jose A. Blakeley and Michael PizzoADO.NET Entity Framework by Jose A. Blakeley and Michael Pizzo
ADO.NET Entity Framework by Jose A. Blakeley and Michael Pizzo
 
540slidesofnodejsbackendhopeitworkforu.pdf
540slidesofnodejsbackendhopeitworkforu.pdf540slidesofnodejsbackendhopeitworkforu.pdf
540slidesofnodejsbackendhopeitworkforu.pdf
 
XXE Exposed: SQLi, XSS, XXE and XEE against Web Services
XXE Exposed: SQLi, XSS, XXE and XEE against Web ServicesXXE Exposed: SQLi, XSS, XXE and XEE against Web Services
XXE Exposed: SQLi, XSS, XXE and XEE against Web Services
 
Native Phone Development 101
Native Phone Development 101Native Phone Development 101
Native Phone Development 101
 
Introducing the WSO2 Complex Event Processor
Introducing the WSO2 Complex Event ProcessorIntroducing the WSO2 Complex Event Processor
Introducing the WSO2 Complex Event Processor
 
Lightbend Lagom: Microservices Just Right (Scala Days 2016 Berlin)
Lightbend Lagom: Microservices Just Right (Scala Days 2016 Berlin)Lightbend Lagom: Microservices Just Right (Scala Days 2016 Berlin)
Lightbend Lagom: Microservices Just Right (Scala Days 2016 Berlin)
 
Complex Event Processor 3.0.0 - An overview of upcoming features
Complex Event Processor 3.0.0 - An overview of upcoming features Complex Event Processor 3.0.0 - An overview of upcoming features
Complex Event Processor 3.0.0 - An overview of upcoming features
 
Lets have some fun with twilio open tok
Lets have some fun with   twilio open tokLets have some fun with   twilio open tok
Lets have some fun with twilio open tok
 
Understanding Reflection
Understanding ReflectionUnderstanding Reflection
Understanding Reflection
 
Using the Tooling API to Generate Apex SOAP Web Service Clients
Using the Tooling API to Generate Apex SOAP Web Service ClientsUsing the Tooling API to Generate Apex SOAP Web Service Clients
Using the Tooling API to Generate Apex SOAP Web Service Clients
 
XAML/C# to HTML/JS
XAML/C# to HTML/JSXAML/C# to HTML/JS
XAML/C# to HTML/JS
 
IronSmalltalk
IronSmalltalkIronSmalltalk
IronSmalltalk
 
RIA services exposing & consuming queries
RIA services exposing & consuming queriesRIA services exposing & consuming queries
RIA services exposing & consuming queries
 
The use case of a scalable architecture
The use case of a scalable architectureThe use case of a scalable architecture
The use case of a scalable architecture
 
PCI Security Requirements - secure coding
PCI Security Requirements - secure codingPCI Security Requirements - secure coding
PCI Security Requirements - secure coding
 
Jeff English: Demystifying Module Development - How to Extend Titanium
Jeff English: Demystifying Module Development - How to Extend TitaniumJeff English: Demystifying Module Development - How to Extend Titanium
Jeff English: Demystifying Module Development - How to Extend Titanium
 
.Net 3.5
.Net 3.5.Net 3.5
.Net 3.5
 
Using Webservice in iOS
Using Webservice  in iOS Using Webservice  in iOS
Using Webservice in iOS
 
Intro to Node
Intro to NodeIntro to Node
Intro to Node
 

Plus de Tomas Petricek

Queries in general purpose languages
Queries in general purpose languagesQueries in general purpose languages
Queries in general purpose languages
Tomas Petricek
 

Plus de Tomas Petricek (15)

Coeffects: A Calculus of Context-Dependent Computation
Coeffects: A Calculus of Context-Dependent ComputationCoeffects: A Calculus of Context-Dependent Computation
Coeffects: A Calculus of Context-Dependent Computation
 
F# Data: Making structured data first class citizens
F# Data: Making structured data first class citizensF# Data: Making structured data first class citizens
F# Data: Making structured data first class citizens
 
Doing data science with F# (BuildStuff)
Doing data science with F# (BuildStuff)Doing data science with F# (BuildStuff)
Doing data science with F# (BuildStuff)
 
Doing data science with F#
Doing data science with F#Doing data science with F#
Doing data science with F#
 
F# and Financial Data Making Data Analysis Simple
F# and Financial Data Making Data Analysis SimpleF# and Financial Data Making Data Analysis Simple
F# and Financial Data Making Data Analysis Simple
 
Information-rich programming in F# (ML Workshop 2012)
Information-rich programming in F# (ML Workshop 2012)Information-rich programming in F# (ML Workshop 2012)
Information-rich programming in F# (ML Workshop 2012)
 
Asynchronous programming in F# (QCon 2012)
Asynchronous programming in F# (QCon 2012)Asynchronous programming in F# (QCon 2012)
Asynchronous programming in F# (QCon 2012)
 
Queries in general purpose languages
Queries in general purpose languagesQueries in general purpose languages
Queries in general purpose languages
 
Docase notation for Haskell
Docase notation for HaskellDocase notation for Haskell
Docase notation for Haskell
 
F# on the Server-Side
F# on the Server-SideF# on the Server-Side
F# on the Server-Side
 
F# Tutorial @ QCon
F# Tutorial @ QConF# Tutorial @ QCon
F# Tutorial @ QCon
 
Teaching F#
Teaching F#Teaching F#
Teaching F#
 
F# in MonoDevelop
F# in MonoDevelopF# in MonoDevelop
F# in MonoDevelop
 
Academia
AcademiaAcademia
Academia
 
Concurrent programming with Agents
Concurrent programming with AgentsConcurrent programming with Agents
Concurrent programming with Agents
 

Dernier

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Dernier (20)

DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 

F# Type Providers in Depth

  • 1. F# Type Providers in Depth Tomas Petricek @tomaspetricek | http://tomasp.net
  • 2.
  • 3. F# 3.0 in Visual Studio 11
  • 4. The Problem Meta-data <s:complexType name="Session"> <s:sequence> <s:element minOccurs="0" maxOccurs="1" information name="CustomerID" type="s:string" /> <s:element minOccurs="0" maxOccurs="1" name="CustomerName" type="s:string" /> ≠ <s:element minOccurs="0" maxOccurs="1" name="BranchNumber" type="s:string" /> <s:element minOccurs="0" maxOccurs="1" F# type name="SessionKey" type="s:string" /> <s:element minOccurs="0" maxOccurs="1" name="ChosenDeliverySlotInfo" declaration type="s:string" /> <s:element minOccurs="0" maxOccurs="1" name="CustomerMessageOfTheDay" type="s:string" /> type Session = <s:element minOccurs="0" maxOccurs="1" name="CustomerForename" { CustomerID : int type="s:string" /> CustomerName : string </s:sequence> </s:complexType> BranchNumber : int SessionKey : string ChosenDeliverySlotInfo : string CustomerMessageOfTheDay : string CustomerForName : string }
  • 6. Levels of Data Access Expression Scale Program Scale Dynamic typing Code generation Internet Scale Type providers
  • 7. Type providers change how you think about programming!
  • 8.
  • 10. What is a Type Provider?
  • 11. How are Type Providers used? Type provider IDE Compiler IntelliSense for Type-Check Compile using Generated Types Imported Types Type Provider
  • 12. Type Providers for .NET Hiding code generation Web Services (WSDL) SQL databases (LINQ to Entities) Erasing provided types REST services (World Bank) Schematized web (Freebase)
  • 14. 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 }
  • 15. Implementing Type Providers public interface ITypeProvider { Type[] GetTypes(); Expression GetInvokerExpression ( MethodBase method, ParameterExpression[] params ); event EventHandler Invalidate; }
  • 16. Design Considerations Choosing the right view Provide the right projection Inferring structure from data Schema structure Refreshing the schema Caching of online schema
  • 17. DEMO: XML TYPE PROVIDER
  • 18. Summary The ease of dynamic languages Generate types from schema No actual types are needed With the static typing benefits Checked at compile-time Full IntelliSense support
  • 19. Compile-Time vs. Run-time Type Provider Runtime API Provider Accesses Data Generates source Uses Accesses Provided code Executable
  • 20. Compile-Time vs. Run-time Type Provider Runtime API Provider Accesses Data Generates source Provided code Executable
  • 21. 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 ])