Building Type Providers for F#
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.
F# Data Library
by
Tomas Petricek
FSharpX is more general purpose package that contains "a bit of everything" and changes more organically. It has more features, but lacks some stability and documentation. However, FSharpX contains other type providers (including Xaml, Graph, Regex, etc.) that are not focused on data access and will not probably appear in F# Data (because they serve different purpose).
So, I think F# Data should be a better starting point for those interested in data access in F#.
Educational Content
Clojure in the Field
Stuart Halloway May 23, 2013
Tuning the Size of Your Thread Pool
Kirk Pepperdine May 23, 2013




Hello stranger!
You need to Register an InfoQ account or Login to post comments. But there's so much more behind being registered.Get the most out of the InfoQ experience.
Tell us what you think