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>     ...
The Problem
Levels of Data AccessExpression Scale       Program Scale  Dynamic typing        Code generation            Internet Scale...
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...
Type Providers for .NETHiding code generation Web Services (WSDL) SQL databases (LINQ to Entities)Erasing provided types R...
DEMO: WSDL, SQL, ODATA
Queries in F#Can be turned to quotations     query { for movie in netflix.Titles do             where (movie.Name.Contains...
Implementing Type Providers public interface ITypeProvider {    Type[] GetTypes();     Expression GetInvokerExpression    ...
Design ConsiderationsChoosing the right view  Provide the right projection  Inferring structure from dataSchema structure ...
DEMO: XML TYPE PROVIDER
SummaryThe ease of dynamic languages  Generate types from schema  No actual types are neededWith the static typing benefit...
Compile-Time vs. Run-timeType Provider      Runtime API      Provider                                     Accesses        ...
Compile-Time vs. Run-timeType Provider      Runtime API      Provider                                     Accesses        ...
Structure of a Simple Provider[<TypeProvider>]type SampleTypeProvider(config: TypeProviderConfig) =  inherit TypeProviderF...
F# Type Providers in Depth
F# Type Providers in Depth
Upcoming SlideShare
Loading in …5
×

F# Type Providers in Depth

4,430 views

Published on

Talk slides from the Functional Programming eXchange 2012 on F# type providers. Examples include WorldBank data, SQL, OData and WSDL as well as structure inference for XML files.

Published in: Technology
1 Comment
1 Like
Statistics
Notes
No Downloads
Views
Total views
4,430
On SlideShare
0
From Embeds
0
Number of Embeds
11
Actions
Shares
0
Downloads
35
Comments
1
Likes
1
Embeds 0
No embeds

No notes for slide

F# Type Providers in Depth

  1. 1. F# Type Providers in Depth Tomas Petricek @tomaspetricek | http://tomasp.net
  2. 2. F# 3.0 in Visual Studio 11
  3. 3. 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 }
  4. 4. The Problem
  5. 5. Levels of Data AccessExpression Scale Program Scale Dynamic typing Code generation Internet Scale Type providers
  6. 6. Type providers change how you think about programming!
  7. 7. DEMO: WORLD BANK
  8. 8. What is a Type Provider?
  9. 9. How are Type Providers used? Type provider IDE Compiler IntelliSense for Type-Check Compile usingGenerated Types Imported Types Type Provider
  10. 10. Type Providers for .NETHiding code generation Web Services (WSDL) SQL databases (LINQ to Entities)Erasing provided types REST services (World Bank) Schematized web (Freebase)
  11. 11. DEMO: WSDL, SQL, ODATA
  12. 12. 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 }
  13. 13. Implementing Type Providers public interface ITypeProvider { Type[] GetTypes(); Expression GetInvokerExpression ( MethodBase method, ParameterExpression[] params ); event EventHandler Invalidate; }
  14. 14. Design ConsiderationsChoosing the right view Provide the right projection Inferring structure from dataSchema structure Refreshing the schema Caching of online schema
  15. 15. DEMO: XML TYPE PROVIDER
  16. 16. SummaryThe ease of dynamic languages Generate types from schema No actual types are neededWith the static typing benefits Checked at compile-time Full IntelliSense support
  17. 17. Compile-Time vs. Run-timeType Provider Runtime API Provider Accesses Data Generates source Uses Accesses Provided codeExecutable
  18. 18. Compile-Time vs. Run-timeType Provider Runtime API Provider Accesses Data Generates source Provided codeExecutable
  19. 19. 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 ])

×