Version 1.12 of the F# C# MVC 4 Visual Studio extension now includes a Single Page Application (SPA) template with the Backbone.js JavaScript framework. The template works in VS2010 as well as VS2012 (including VS2012 Express for Web).

To use the new template, simply pull down the latest by following the direction from one of my previous posts or by clicking the download button on Visual Studio Gallery. Once you have installed the Visual Studio extension, you will see the following screen when creating a new F# and C# Web Application (ASP.NET MVC 4) from the Visual F# | ASPNET project template category.

Highlights of the F# and C# project structure are shown below:


If you wish to learn more about the solution that is generated from this new template, see my previous post.

A Few New NoSQL Helper Libraries

On July 9, 2012, in Uncategorized, by Dan Mohl

I’ve been working on a few new libraries lately that focus on providing functional wrappers around various NoSQL options.


FSharpCouch is something that I wrote about a little over two years ago. At the time, it was more of an educational exercise, but I have since revised it and found aspects of it to be useful. This is now available on NuGet as package ID FSharpCouch.

Here’s an example:

You can find additional examples and the full source at


MongoFs currently has a primary focus on function composition as it relates to setting up the MongoDB client aspects of server, database, and collection. It simply wraps functions around the necessary methods of the C# Mongo Driver and auto opens the encompassing module.

Here’s an example:

You can get it from NuGet as package ID MongoFs and find more examples as well as the source at

Tagged with:  

The F#/C# ASP.NET MVC 4 template has been updated to support ASP.NET MVC 4 RC and Visual Studio 2012 RC. You will need to install the release candidate of ASP.NET MVC 4 to use this updated version of the template. The install can be found at

As with the previous release, the F#/C# ASP.NET MVC project template supports ASPX and Razor versions of an empty ASP.NET MVC 4 project template as well as a Razor version of the ASP.NET Web API project template. The templates work on both VS2010 and VS2012 RC.

Tagged with:  

Fog Released

On May 24, 2012, in Uncategorized, by Dan Mohl

A new release of Fog is now available. The primary enhancement included in this release is support for Windows Azure Caching. Several bug fixes have also been included.

The caching functions are available in the Fog.Caching module. You can use them with code such as the following:

type TestRecord = 
    { [<DataMember>] mutable Id : Guid
      [<DataMember>] mutable Name : string }

let testRecord = { Id = Guid.NewGuid(); Name = "Dan" }

let key = testRecord.Id.ToString()  
Put key testRecord |> ignore

let result = Get<TestRecord> key

Fog is available via NuGet as ID Fog and the full source can be found on my GitHub.

Tagged with:  

Fog is a library that makes it easier to use F# to interact with Windows Azure through the Windows Azure SDK for .NET. It provides functions for many of the common activities related to table storage, blob storage, and queue storage as well as service bus queues and topics. Provided functions include both course and fined-grained approaches that remove boiler plate code and make it easier to use various functional patterns and techniques. The course grained functions currently use config settings with specific names to allow most operations to only require a single function call.

The syntax of Fog is pretty straight forward. The following examples use the course grained approach. To see how to use the fined-grained functions, which match almost one to one with the Azure SDK for .NET methods, see the Fog integration tests.

Blob Storage

With Fog all you have to do to interact with Azure blob storage is to add the connection string information in the config with a name of “BlobStorageConnectionString”. Once that is done, you can use syntax like the following:

UploadBlob "testcontainer" "testblob" "This is a test" |> ignore 
DeleteBlob "testcontainer" "testblob" 


UploadBlob "testcontainer" "testblob" testBytes |> ignore 
DownloadBlob<byte[]> "testcontainer" "testblob"

Table Storage

The simplest way to interact with Azure table storage is to add the connection string information in the config with a name of “TableStorageConnectionString”. Once that is done, you can use syntax like the following:

[<DataServiceKey("PartitionKey", "RowKey")>] 
type TestClass() = 
    let mutable partitionKey = "" 
    let mutable rowKey = "" 
    let mutable name = "" 
    member x.PartitionKey with get() = partitionKey and set v = partitionKey <- v 
    member x.RowKey with get() = rowKey and set v = rowKey <- v 
    member x.Name with get() = name and set v = name <- v 

let originalClass = 
    TestClass( PartitionKey = "TestPart", RowKey = Guid.NewGuid().ToString(), Name = "test" ) 

CreateEntity "testtable" originalClass |> ignore 

let newClass = originalClass 
newClass.Name <- "test2" 

UpdateEntity "testtable" newClass |> ignore 
DeleteEntity "testtable" newClass 

Queue Storage

For queue storage, add the connection string configuration value with setting name “QueueStorageConnectionString”.

AddMessage "testqueue" "This is a test message" |> ignore 
let result = GetMessages "testqueue" 20 5 
for m in result do 
    DeleteMessage "testqueue" m 

Service Bus

There are a few service bus related config entries. Here’s the list of expected names: ServiceBusIssuer, ServiceBusKey, ServiceBusScheme, ServiceBusNamespace, ServiceBusServicePath

To send a message do this:

type TestRecord = { Name : string } 
let testRecord = { Name = "test" } 

SendMessage "testQueue" testRecord 

To receive a message, pass the queue name, a function to handle successful message retrieval, and another function to handle errors.

HandleMessages "testQueue" 
    <| fun m -> printfn "%s" m.GetBody<TestRecord>().Name
    <| fun ex m -> raise ex 

To use topics in a pub/sub type of scenario, use something like the following to subscribe:

Subscribe "topictest2" "AllTopics4" 
    <| fun m -> printfn "%s" m.GetBody<TestRecord>().Name 
    <| fun ex m -> raise ex 

Message publishing can be accomplished like this:

Publish "topictest2" testRecord 

A few other handy functions include Unsubscribe and DeleteTopic:

Unsubscribe "topictest2" "AllTopics4" 
DeleteTopic "topictest2" 

How to get it

The easiest way to get Fog is to install the Fog NuGet package. You can also find the full source as well as integration tests on the Fog GitHub site.

Tagged with:  

F#, MSTest, and FsUnit

On April 23, 2012, in Uncategorized, by Dan Mohl

I’ve been very busy with a few side projects that I plan to talk more about soon. Sadly, my blog has suffered due to these other activities, but I wanted to take a few minutes to talk about a new MSTest project template available on Visual Studio Gallery as well as some activity going on with FsUnit.

MSTest Project Template:

In the first week of March I released a new project template that helps in the creation of unit tests with MSTest and VS11. You can find it at or by searching for “fsharp mstest” in the Visual Studio Gallery online templates.


FsUnit has also had a few enhancements.

1. Support for MsTest has been added for VS11 and made available through a new NuGet package named Fs30Unit.MsTest.

2. A few new assertions have been added for NUnit including NaN, instanceOfType, and unique.

3. FsUnit has long supported a function named “not”. While this is a nice feature, the fact that it overwrites an F# operator is not ideal. Because of this, version renames this function to not’. For the purpose of backward compatibility, you can open the module named FsUnitDepricated to make the “not” function available.

One last thing. If you’re using FsUnit with NUnit, MbUnit, or xUnit in VS11 Beta, you will need to add binding redirects from previous versions of FSharp.Core to version The easiest way to do this is to use the Add-BindingRedirect PowerShell cmdlet provided by NuGet ( Here are the steps:

1. After installing one of the FsUnit NuGet packages, create an App.config file (if one doesn’t already exist).

2. In the NuGet Package Manager Console, run the following command “Add-BindingRedirect projectname” after replacing projectname with the name of your test project.

Tagged with:  

A Nice Addition to the Empty WPF F# Template

On March 26, 2012, in Uncategorized, by Dan Mohl

A few days ago Steffen Formann announced a Xaml type provider that he and Johann Deneux have created that makes writing WPF apps in F# very easy. This type provider allows strongly typed access to the XAML, effectively providing the missing piece to allowing full F# WPF designer support. I’ve now updated the Empty WPF F# Template to include this type provider.

To use it, all you have to due is download/install the latest version of the F# Empty Windows App (WPF) template in VS11. This will generate an F# project with all the needed WPF assembly references. It also automatically installs the FSharpx.TypeProviders NuGet package and provides the starting point for creating WPF apps with the new Xaml type provider.

Here’s a screenshot that’s pretty similar to what Steffen showed in the announcement post. Note: The button and label were manually added after creating the project from the updated template.

One other piece that can be helpful when creating WPF apps in F# is the XAML related item templates (i.e. Page, User Control, Window, etc). Item templates are provided via the F# XAML Item Templates extension found at

Tagged with:  

F# and ASP.NET Web API

On March 5, 2012, in Uncategorized, by Dan Mohl

A few weeks ago the ASP.NET team announced the release of ASP.NET MVC 4 Beta. You can read about it here. One of the exciting features that was announced is ASP.NET Web API. ASP.NET Web API provides an excellent programming model for building HTTP services.

One of the sweet spots for F# is in the services layer and this makes ASP.NET Web API + F# great friends. To make it easy to get started with F# and ASP.NET Web API, I’ve added an ASP.NET Web API template to the already existing F#/C# ASP.NET MVC 4 Visual Studio extension. Note: The template requires that ASP.NET MVC 4 Beta is installed.

To install the template, do the following:

1. Launch the project creation wizard (Ctrl+Shift+N), select Online in the left hand nav, search for “fsharp mvc4″, and click OK. In VS11 Beta, it looks something like the following. Note: It may take a few seconds to download.

2. After clicking OK and installing the extension, you will see a dialog that allows the creation of a new ASP.NET Web API solution with an F# project that contains the server-side code.

3. Once the project has been created, you can run it however you desire and hit the service via http://localhost:###/api/values.

Tagged with:  

There’s a new version of the F#/C# ASP.NET MVC 3 internet Project Template. This version allows you to choose between the ASPX and Razor view engines.

Here’s how to use it:

1. Install version 1.6+ of the project template by searching for it on Visual Studio Gallery and/or updating a version that you had previously installed.

2. Create a new project.

3. You will now see a dialog box similar to what is shown below:

While it’s certainly not required in order to use this template, you can see the full source on my GitHub.

Tagged with:  

Another Way to Kick-start F# WPF Apps

On February 6, 2012, in Uncategorized, by Dan Mohl

Over the last few years I’ve announced a number of project templates that are available on Visual Studio Gallery. A few of these have provided ways to kick-start F# WPF apps. I talked about one of these templates here. While these are nice for getting acquainted with building WPF apps in F# and/or F#+C#, the files needed for the included sample app may become a bother once you have a few of these apps under your belt. Because of this, I’ve released an F# only Empty WPF project template (an F#/C# Empty WPF template will likely be coming soon).

To get the new template, do the following:

1. In Visual Studio 2010 or 11, navigate to File -> New and select Online Templates (or just Online if using VS11).

2. Search for “Daniel Mohl” or “F# Empty Windows App” as shown below:

3. Select the template, click OK, and agree to the install.

While it’s certainly not required to use the template, you can find the full source on my GitHub.

Tagged with: