Type Providers are an interesting feature of F#. From the developer’s perspective, they are like any of statically defined type. But rather than coming from the metadata of a CLR assembly, they are created as needed by code that is executed at design time. The source can be anything, with databases and REST or OData style web services being the most common option.
In a 2011 article, Ivan Towlson demonstrated how developers can create type providers to reduce boilerplate in code that doesn’t look at external services. His example created vector types of varying lengths, as well as the common operations that apply to the same.
Since the work by him and others has been moved into the FSharpx project. In it you’ll find nine sets of type providers to use directly or as inspiration for creating your own.
- FSharpx.TypeProviders.AppSettings
- FSharpx.TypeProviders.Documents
- FSharpx.TypeProviders.Excel
- FSharpx.TypeProviders.Freebase
- FSharpx.TypeProviders.Graph
- FSharpx.TypeProviders.Machine
- FSharpx.TypeProviders.Math
- FSharpx.TypeProviders.Regex
- FSharpx.TypeProviders.Xaml
FSharpx is an open source project offered under the Apache License, Version 2.0.
For those who rely on the statistical analysis language R, Blue Mountain is offering an F# R Type Provider. This type provider is also offered as an open source project, with a non-standard but very lenient license.
For more information on F# type providers see Joe Pamer’s video The Future of F#: Type Providers and the Microsoft Research paper F#3.0 - Strongly-Typed Language Support for Internet-Scale Information Sources.
It may also be useful to look at other languages that offer similar capabilities. One such language is Gosu. This JVM-based language uses what they call the Open Type System. Cédric Beust has a good introduction to the Open Type System with plenty of links to more in depth discussions.