Advice for Getting Started with F#

I had a great time at NYC Code Camp this last weekend. About half the people in my talk already knew F# and were there to talk about Type Providers, the other half just came to see what this F# thing was all about. This post is to help those in the second half begin their F# learning adventure.

The first thing anyone who is looking to get started with F# should do is work through the tutorial examples on tryfsharp.org. Getting some hands-on time with the basics is extremely important, especially if you haven’t done much functional programming before.

Once you’ve got the basics down, the next step is thinking through some real problems in F#. For me, this was writing an Ant Colony simulation. With the version linked to here you can actually compile and then try your own ant behavior code against mine! Other great options include the Coding Dojo Katas or Project Euler (for the mathematically inclined).

It’s best if you do most of your play using .fsx files and F# interactive at first. Just highlighting code and hitting Alt-Enter makes the process of learning so much faster. However, if you insist on working with unit tests I suggest Xunit as it doesn’t require the use of classes for hosting your tests.

At first it’s also best to ignore most of F#’s features, it can be overwhelming otherwise. Try your best to focus on comprehensions. These may not always be the best way to solve a problem, but they allow you to write very imperative code right in the middle of a bunch of functional stuff and so are kind of an escape hatch for when you don’t know how to do what you want functionally. Eventually you’ll want to move on to recursion and folding though. When you’re ready to make the jump read this post which talks about how to go about it.

As you’re playing with F#, don’t be afraid to look things up along the way when you get stuck. There’s quite a few good resources around for F# including the F# Programming WikiBook, the code samples provided by the F# team, and a number of print books including Professional F# 2.0 (shameless plug). When all else fails the MSDN documentation for F# is actually very good!

I can say from experience that at first you will likely experience quite a few syntax errors. Don’t worry too much about it, your brain needs to build up a model of how the types and syntax work. Once you’ve gotten over that hurdle I promise you’ll be amazed by how different the programming world looks.

Tags: , ,

5 comments

  1. Try Nemerle from Nemerle.org. It is much better than F#

    • Nemerle is a fine language, but it’s not a real Microsoft language and so has no real support or guaranteed future. Good luck getting it into any corporate environment.

      Also, I find the syntax to be a bit ugly and excessive. It’s like someone tried to dress F# up into C#’s clothing but couldn’t quite make it fit. The type inference is not nearly as robust, it lacks many of the convenience features and there’s no news of anything like Type Providers.

      The Macro system is pretty cool though.

  2. [...] Advice for Getting Started with F# (Rick Minarich) [...]

  3. [...] also had the pleasure of speaking at a quite a few interesting events this year. One I haven’t yet written about is Monospace 2011. Click For [...]

  4. [...] Advice for getting started with F# by Richard Minerich An overview of functional programming by Dorian Corompt (recursion, lists, more to come…) [...]

Leave a comment