Building Type Providers for F#

| by Jonathan Allen on Dec 29, 2012. Estimated reading time: 1 minute |

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.

Rate this Article


Hello stranger!

You need to Register an InfoQ account or 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

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

F# Data Library by Tomas Petricek

It might be worth adding that, in addition to FSharpX, there is also a newer F# Data Library which aims to be a simpler and more focused package that contains the key F# type providers for data access (including XML, CSV, JSON and WorldBank database). The library includes better inference engine, so it generates types that are easier to use (especially for XML and JSON), it is easier to use and it comes with a comprehensive documentation and examples. The library will eventually become a part of the F# organization on GitHub, but there are a few minor updates that need to be done before that.

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#.

Re: F# Data Library by Jonathan Allen

Thanks for the heads up. That looks like a pretty cool project and we'll definitely try to get some more coverage for them.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

2 Discuss