F#

Getting started with F# : read a book!

November 11th, 2008

Recently, a colleague here at Lab49 asked whether there were any good books available to help getting developers unfamiliar with F# and functional programming started in the world of functional .NET. I had some ideas and thought I’d post them here.

(In his post below, Sergey mentioned that Luke Hoban, the F# product manager, gave a talk at the Lab on F#. We recorded that presentation and I’ll be posting it soon, so stay tuned.)

The question was if there was a good book for “a typical Java developer to learn F#”. The short answer is that there isn’t. F# is a pretty flying leap for a typical Java developer to make; you can approach F# from the .NET world (e.g. C#) or from other functional languages (e.g. its parent, OCaml), but it’s hard to see how one could do it from neither. That said, I know of three F#-focused books in print now that can serve as a guide:

-”Expert F#“, by F#’s creator Don Syme. This is the book I recommend. It’s not perfect but it’s a good introduction to F#, mostly suited for people coming from a .NET background. It’s very dense. It’s not for novice programmers, and assumes a good deal of expert general programming knowledge on the part of the reader. But it’s definitely the best out there. (It’s also a bit out of date since the release of the September 1.9.6.2 CTP, but still mostly relevant. I expect it will eventually get updated.)

-”Foundations of F#” by Robert Pickering. This one is simpler and more basic than the above, and might be useful for just getting started. It isn’t as illuminating as the above and won’t serve as a full guide on its own. If you’re ready to deep dive, go straight to Don Syme and pass this one by.

-”F# for Scientists.” This one is for scientists.

“Expert F#” is the best bet for really tackling this language.

Keep in mind that if you really want to get serious with F# as a platform you’ll eventually need to understand the .NET Framework and the CLR (for which the best book remains “CLR via C#” by Jeffrey Richter).

There are a couple of other books coming out that I’m looking forward to seeing. One, by Chris Smith, promises to be great and is slated for release next year (and has a truly bizarre image occupying its placeholder cover). Also check out Chris’s series on his blog solving Project Euler problems with F#, which show off some of F#’s core functionality and can be a nice intro to approaching problems in a functional way. Another, “Real-world Functional Programming in .NET” by Tomas Petricek, who used to work on the F# team, will deal with FP approaches in both .NET and C# (using LINQ).

Some other F# resources are:
Hubfs.com, where the minds behind F# monitor the boards and answer tough questions, and
Flying Frog Consultancy, who have done a lot of cool work with F#.

My advice: download the CTP, buy the Don Syme book, and have some functional fun.

let F# = succinct

November 11th, 2008

A while ago Luke Hoban from Microsoft gave a presentation on F#. I started reading the F# book by Don Syme and the word that was often used to describe the language in both the book and the presentation was “succinct”.

I decided to test the succinctness of it and here is my implementation of Quick Sort in F#

 let rec quickSort sequence =
  match sequence with
  | [] -> sequence
  | x :: t -> List.partition (fun a -> a < x) t |> (fun (a,b) -> quickSort a @ x :: quickSort b)

Pretty Succinct!

Experimental Feature in F#

January 30th, 2008

I’ve been looking for opportunities to express myself in F# and I found a good idea on Hubfs:

http://cs.hubfs.net/blogs/solong/archive/2008/01/14/4561.aspx

The idea is to solve problems at ProjectEuler in F#
http://projecteuler.net/index.php?section=problems

While implementing the solution for problem #2 in F#, I learned about an experimental feature. fun fun. Read the rest of this entry »

Implementation of Software Transactional Memory for F#

January 17th, 2008 / Development in a Blink

via Don Syme Greg Neverov’s post. The library exposes memory transactions as a monad using F#’s new computation expression feature. Download HERE.