What is the advantage of type F # providers over traditional type providers?

On the page

+6
source share
2 answers

In many ways, code generation is a natural comparison for type providers. However, type providers have several desirable properties that are missing from code generation:

  • Type providers can be used in F # scripts without the need for context switching. With a code generator, you have to call the generator, reference the code, etc. With a type provider, you reference the type provider assembly (which looks like a reference to any other F # /. NET assembly), and then use the provided types immediately. This is truly a game changer for interactive scripts.
  • As Gustavo mentions, erasable types allow type providers to handle situations where traditional code generation generates too much code (for example, Freebase has thousands of types, which is not a problem for the type provider).
  • Type providers may support invalidation, so if the data source is changed, the compiler immediately double-checks the file.
  • Similarly, with a code generator, it is possible for the generated code to go out of sync with the data source; type providers can prevent this problem by checking the data source every time your program is compiled (although many type providers also provide the ability to use a cached scheme for convenience).
  • Type providers may be easier to implement, although this probably depends on the script and background of the author.
+13
source

You can create types from WSDL or from the database using the code generation tool, as integrated into Visual Studio. Type providers do almost the same thing, but integrate this process directly into compilation. This way, you donโ€™t have to worry about type recovery when changing the schema.

Additionally, type providers support this with erasable types that are โ€œvirtualโ€ types that do not actually exist. This means that instead of generating 500 types and a large assembly, only what is actually used is generated, which means smaller assemblies and support for importing huge and recursive schemas like Freebase

+11
source

Source: https://habr.com/ru/post/956087/


All Articles