Volume 26 Number 04
Toolbox - F# Tools and Resources
By Terrence Dorsey | April 2011
F# is a new functional, type-safe programming language for the Microsoft .NET Framework. Developed at Microsoft Research, it’s based on Objective Caml, or OCaml, which is in turn based on ML. The creator of F#, Don Syme, calls it “a synthesis between type-safe, scalable, math-oriented scripting and programming for .NET.”
It may be a relatively young language, but F# has quickly developed a cult following within the programming community. Perhaps that’s because F# lets you build on familiarity with the .NET Framework and Visual Studio. Perhaps it’s because F# combines functional, imperative and object-oriented programming techniques in a single language. Or perhaps it’s because F# is a strongly typed language that also supports the flexibility of compile-time typing.
Whichever aspects of the language appeal to you, here’s a guide to the tools and resources that will help you get the most out of F#.
If you’re using Visual Studio 2010 and the .NET Framework 4, you’ve already installed all the tools you need to start playing with F# 2.0. You can also download a standalone installer for the F# 2.0 tools(bit.ly/fGVQvl) if you want to use F# in a previous version of Visual Studio or in other development environments.
Your next stop for learning about F# should be the Microsoft F# Developer Center (msdn.microsoft.com/fsharp). Here you’ll find documentation, links to examples, blog posts from F# experts and more.
Your core resource is going to be the F# Language Reference (msdn.microsoft.com/library/dd233181) in the MSDN Library. This has all the language details, along with sample code.
As mentioned earlier, Visual Studio 2010 has deep support for F# right out of the box. But if you want to experiment with the language on other machines, or even other OSes, head over to the **Try F#**Web site (tryfs.net), where you can interactively code using F# in a browser-based interpreter.
Those without Visual Studio can grab a trial download as a standalone app or virtual machine from Microsoft (msdn.microsoft.com/vstudio/bb984878). Aside from Visual Studio, there are a number of other free and commercial IDEs that directly support F# development. These include SharpDevelop(sharpdevelop.net/OpenSource/SD), xacc.ide (xacc.wordpress.com) and MonoDevelop (monodevelop.com).
A unique aspect of MonoDevelop is that it enables you to set up your development environment on Windows, Mac OS X or Linux and target .NET Framework-based applications to those platforms in addition to Android, iOS and Windows Phone 7. Functional Variations has details on getting the F# features running; see “Installing and using F# in MonoDevelop” (functional-variations.net/monodevelop). Robert Pickering also has a guide to using F# on Mac OS X and Linux with Mono (http://strangelights.com/blog/) on his F# Resources blog.
And if you’re a die-hard Emacs user, don’t despair: Laurent Le Brun is working on F# IntelliSense in Emacs (bit.ly/f3pd8b). Watch his blog for details.
Tools, Templates and Libraries
There are a variety of tools available to make F# easier and more powerful. Your first download should probably be the F# PowerPack (fsharppowerpack.codeplex.com) from the F# development team. The PowerPack includes source for the F# compiler and code library, plus a number of additional tools and libraries. Among them are a Matrix library, tools for lexing and parsing, LINQ-based data access and tools for documenting F# libraries.
FAKE (github.com/forki/FAKE) is a build-automation system for F# designed with inspiration from tools like make and rake. FAKE lets you leverage both functional programming techniques and direct access to .NET assemblies while also integrating directly with the editing and debugging features of F#-aware IDEs like Visual Studio and SharpDevelop.
Head over to CodePlex to find a couple of handy testing tools: TickSpec (tickspec.codeplex.com) is a Behavior-Driven Development framework that lets you describe behaviors in Gherkin (given, when, then), and then execute the behaviors against C# and F# methods.
FsUnit (fsunit.codeplex.com) is a unit-testing library. Simply drop the FsUnit.fs file into your project, then start writing test fixtures and tests.
And FsCheck (fscheck.codeplex.com) is a randomized testing framework based on the Haskell QuickCheck project that lets you write your test specifications in F#, C# or Visual Basic.
If you’re interested in Windows Phone 7 development, go to the Visual Studio Gallery and grab the F# Library for Windows Phone (XNA) template (bit.ly/h5sg9h) and F# and C# Win Phone App (Silverlight) template (bit.ly/fraF4S) for Visual Studio.
Speaking of Visual Studio again, here are two great projects that will make working with F# much easier: F# Project Extender (fsprojectextender.codeplex.com) helps organize the files in F# projects in Solution Explorer without affecting compilation order; F# Refactor (fsharprefactor.codeplex.com) is developing a toolset for refactoring your F# code (this one’s not quite ready for production work yet, and I’m sure they’d appreciate your contribution; give something back to the community that made all the great tools listed here).
The Web in F#
Websharper (websharper.com) is a framework for writing Web applications in F#. WebSharper 2.1 beta 5 brings F# compatibility extensions for a number of popular Web libraries including Google Maps, Google Visualization, jQuery, Bing Maps, Modernizr, InfoVis and Protovis.
Among his many contributions to the F# community, Tomas Petricek developed F# Web Tools (tomasp.net/projects/fswebtools.aspx), which helps you author client/server/database Web apps with F# and LINQ. Be sure to watch Petriceck’s blog (tomasp.net/blog) for F# news, tips and tricks. Petricek was a member of the Microsoft Research team that created F# and thus has a unique insight into the language.
Remember we said “contributions”? Well, Petricek also created F# Snippets (fssnip.net), a site where you can share and borrow F# code snippets for hundreds of different uses. The site features full syntax highlighting and type information.
A bit more useful for math enthusiasts and number crunchers, VSLab (vslab.codeplex.com) provides an F#-based interactive visualization environment similar to Matlab within Visual Studio.
VSLab Math Visualizations in Visual Studio
To help you learn F#, Chris Marinos started an ongoing project called F# Koans (bit.ly/hovkxs). Inspired by the Ruby Koans approach to learning the Ruby language, F# Koans teaches you the fundamentals and deeper truths of F# through testing. Each koan solution presents a runtime error. Your goal is to make the error go away. By fixing the errors you gain knowledge of the F# language and functional programming. Check out Marinos’ blog for more F# tidbits at chrismarinos.com.
Reading Is Fundamental
Many of us rely on good old-fashioned books—and increasingly, ebooks—for learning new skills and as resources we refer to for language details and for implementation techniques. Here are a few you might turn to when adding F# to your quiver of skills.
Expert F# 2.0
“Expert F# 2.0” (Apress, 2010) (http://www.apress.com/9781430224310), by Don Syme, Adam Granicz and Antonio Cisternino, is an authoritative guide to the language by its inventor and two leading members of the F# development community. You’ll learn how to use F# with .NET technologies including ASP.NET, LINQ, Windows Presentation Foundation and Silverlight. You can get “Expert F# 2.0” in print and ebook formats, including a Kindle edition.
Another reference for developers is “Programming F#” (O’Reilly, 2009) (shop.oreilly.com/product/9780596153656.do), by Chris Smith, who worked on the F# development team at Microsoft. Smith walks you through using F# to solve problems with functional, imperative and object-oriented programming techniques so you can see the full capabilities of the language. There’s also an overview of the F# libraries. “Programming F#” is available in print and a variety of ebook formats, including a Kindle edition.
Flying Frog Consultancy (ffconsultancy.com) specializes in functional programming and technical computing. The company offers a number of interesting publications on F#, including “Visual F# 2010for Technical Computing,”“F# forNumerics,”“F# for Visualization” and the monthly “F# Journal.” It also has a selection of other books on OCaml and data analysis techniques. Deeply geeky stuff! Don’t forget to check out its F# News blog(fsharpnews.blogspot.com) for news, analysis, examples and job listings for developers with experience in F# and functional programming.
From the outside it might seem as if F# is a niche technology, but there’s a huge, enthusiastic community growing around it. To join in, start by hanging around some of these popular sites on the Web:
hubFS: THE place for F# (cs.hubfs.net) hosts a news feed, blogs and discussion forums for F# programmers.
In addition, here are some key people in the F# community whose blogs you may want to peruse for tips and tricks:
Gordon Hogenson (blogs.msdn.com/gordonhogenson) is the technical writer who wrote most of the MSDN documentation for F#.
Richard Minerich (richardminerich.com) does a fantastic job of sharing blog posts and news about F# and other interesting topics. You can follow him on Twitter too, for the real-time F# experience (twitter.com/rickasaurus).
Dan Mohl (bloggemdano.blogspot.com) is an F# Insider and Microsoft MVP who blogs extensively about F# and Microsoft. Mohl has been keeping up on F#-related NuGet packages, so turn to him if you want the latest news.
Don Syme (blogs.msdn.com/dsyme), as the creator of F#, uses his blog to share some great insights into how the language works and what you can expect in future releases. You’ll also find breaking news about F# here.
Thanks to the following technical experts for reviewing this article: Chris Marinos and Richard Minerich