Phil Trelford's Array
POKE 36879, 255

F# Type Providers

March 23, 2014 16:14 by phil

Type Providers are a mature language feature of F# 3 that provide instant typed access, with code completion, to a wide variety of data sources, without requiring code generation. As a language feature, F# Type Providers are cross platform, meaning they can be accessed on Windows via .Net, or on Mac and Linux using the Mono runtime.

If you’re interested in using Type Providers pop down to Skills Matter this Thursday for a Type Provider Treasure Hunt with Tomas Petricek, or Creating Type Providers Hands On with Michael Newton on May 1st.

Much Text

CSV, JSON and XML Type Providers are all available from the community open source FSharp.Data project.

What’s the weather like in London now?

type Weather = JsonProvider< "weather.json" >
let url = "http://api.openweathermap.org/data/2.5/weather?units=metric&q="
let weather = Weather.Load(url+"London")
weather.Main.Temp

Nuget stats on FSharp.Data from an HTML table?

type NugetStats = HtmlProvider<"https://www.nuget.org/packages/FSharp.Data">
let rawStats = NugetStats().Tables.Table0

Many Database

Early type providers allowed access to SQL databases via a connection string, DBML and EDMX files or Entity framework.

The open source SqlClient provider lets you explore queries, stored procedures, user defined types and functions with intellisense.

Access to MS SQL Server, SQLite, PostgreSQL, Oracle and MySQL with full LINQ support is made possible with Ross McKinlay’s SQLProvider.

Connect to the cloud with Isaac Abraham’s Azure Storage Provider.

Or connect to a community-curated database of well-known people places and things with the Freebase provider:

let fb = FreebaseData.GetDataContext()
let astronomy = fb.Society.Celebrities.``Abused substances``

Very Language

Interop seamlessly with the R statistical programming language with the R Type Provider:

open RProvider.``base``
let v = R.c(1,2,3)

Or Matlab, or Java, or Python.

Or Brainfuck

Such Silly

It all started with Ross’s Choose Your Own Adventure Type Provider, and then there was MineSweeper and Battleships.

Now thanks to James you can enjoy FizzBuzz as a Type Provider too:


Have fun!


Tags:
Categories: F# | .Net | Mono
Actions: E-mail | Permalink | Comments (1) | Comment RSSRSS comment feed

Comments

April 26. 2014 09:21

trackback

Date Types

Date Types

Phil Trelford's Array

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading