Search code examples
databasef#language-designtype-providers

What is necessary from a language implementation point of view to implement type providers like in F# 3.0?


F# 3.0 adds type providers, which make it basically unnecessary to manually write or generate mappings between a DB (or another data provider) and the language/type system, because the language can query structural information from the database itself directly with type providers.

What is necessary from a language implementation point of view to add such a feature to a language?

Does it require a fully pluggable type system? Or is it more like some hidden code generator integrated into the compiler?

What's necessary to implement a new type provider for F#?


Solution

  • Technically, you can think of F# type providers as "plugins" for the compiler. Instead of generating mappings, the compiler asks the type provider "What types do you know?" or "Do you know this type?" (depending on the context).

    The plugin (type provider) answers and specifies what the type looks like (abstractly, without actually generating it). The compiler then works with this information and later asks the type provider to provide code that should be used when compiling code that uses these "fake" types. It is also possible to actually generate code (some samples do this, because they just use tools that are already there).

    So yes, you can implement your own type provider. I said a few things about it in the GOTO Copenhagen talk which has been recorded and Don Syme said a few things in his earlier talks (I didn't see his BUILD talk yet).