Stack OverflowGetting started with F#
[+165] [15] Dead account
[2009-04-09 14:39:19]
[ .net f# getting-started ]

What's a good way to get into F# programming?

What's a good "Hello world" example and what simple examples can show me why I want to use it over C#.

Also what tools do I need? I have WindowsXP, Visual Studio 2008 etc.

(2) +1 because it's a 'nice question' - JohnIdol
(1) +1 because it must be the highest voted F# question. - claws
(5) +1 because your surname is Quigley. - Stimul8d
(5) This is StackOverflow. Once you ask a question, it's no longer yours. - codekaizen
(2) @Ian well if they do delete your account for you, you can't stop us putting it all back afterwards :-p But please reconsider. - Rup
(2) Well, Ian, I'm sorry that you are having such a hard time participating in this adult community. I'm really not bothered if you use all your reputation to downvote all of my posts. I'm sure you'll create some lasting memories doing so... - codekaizen
(7) @Ian: this post (and many others that you have initiated) contain a lot of content that was contributed by other people in addition to yourself; I don't think you have the right to unilaterally demand that it is removed or made unusable. Don't you think? - CesarGon
(6) @Ian: If you want your account deleted, send an email to from the email address listed in your profile. - Bill the Lizard
(1) +0 for vandalizing your own question (WTF?) - Mark
(28) ...what on earth happened here? - Zeus
Ian - the Ghost - Henrik
[+177] [2009-04-09 14:42:16] Tarkus [ACCEPTED]

Entry point is here -> Microsoft F# Developer Center [1]

For a quick taste, consider trying F# in your browser [2].

Start by watching videos and presentations (BTW, An Introduction to Microsoft F# [3] by Luca Bolognese is one of the best presentations on the subject). Then read the following two must-read books:

  1. Programming F#: A comprehensive guide for writing simple code to solve complex problems [4] by Chris Smith
  2. Expert F# 2.0 (Expert's Voice in F#) [5] by Don Syme, Adam Granicz, and Antonio Cisternino

And in addition to that:

Quick Links:




Good Books:


Hello World Samples:

Sample 1 [52], Sample 2 [53], Sample 3 [54], Sample 4 [55], Fibonacci Numbers [56], Download Stock Quotes [57]

Code Sample:

// C# :
// using System;
open System
// say hello wrold
printfn "Hello, World! What is your name, user?"
// C# :
// var name = Console.ReadLine();
let name = Console.ReadLine()
// C# :
// public delegate void SaySomethingDelegate(string toWho); 
// SaySomethingDelegatesayHello =
//     who => Console.WriteLine("Hello, {0}!", who);
let sayHello who = printfn "Hello, %s!" who
// hi
sayHello name
// you can using .NET Framework classes and methods:
let sayHelloDotNet who = 
    Console.WriteLine("Hello from F# via .Net, " + name + "!")
// hello again!
sayHelloDotNet name
// let's count Fibonacci
let rec fib i =
  match i with
  | 1 | 2 -> 1
  | i -> fib(i-1) + fib(i-2)

// result
printfn "%i" (fib 20)

Note that there is also a "getting started" small sample as a 'tutorial' project template inside Visual Studio.

Tools needed:

Visual Studio:

If you want F# integrated into Visual Studio, then you either need a non-express version of VS2008, or the VS2008 shell (integrated mode; this component is also a free download [58], linked from the F# download page), or the VS2010 integrated shell ( free download [59]). Then install the CTP MSI.

Or, of course, get a full version of VS2010, where F# is built-in.


You can find lots of information about using F# within MonoDevelop here [60]. The F# compiler and fsi.exe are now part [61] of the Mono distribution.


+1. Thanks. Your editted answer breaks it down into bite sized chunks - Dead account
+1: Informative post, useful beginner code too :) - Juliet
@Ian Quigley, you're welcome! :-) - Tarkus
(3) +F, +A. outstanding value for money! - Dead account
+1 Are you serious.. this list is sickening. - Sung
Thanks for sharing this info so concisely. It really help to get started - Shreedhar
Wow Brian...what a list...a great way to up your rep huh...nonetheless +1 from me .... :) feelin' good already.... - t0mm13b
+1 Detailed and informative answer - Holystream
Great answer. Spot the bug in sayHelloDotNet. :) - Robert Jeppesen
(1) tools: Add LinqPad. It is free and can be used for run simple F# app - Liang Wu
[+29] [2009-04-09 14:50:34] Juliet

F# on Wikibooks [1] is probably the best online resource for beginners wanting to learn F#. Plus its free (as in "free beer"). Feel free to fix all of my spelling/grammar errors as you go through it :)

What's a good "Hello world" example and what simple examples can show me why I want to use it over C#.

If you don't already know F#, its really hard to post an example comparing F# and C# together and say "ah ha! Now you see why this language is so much better" since you don't really know the syntax. But, for what its worth, I wrote this post [2] describing simple symbolic logic in F# and C#, this simple SQL parser [3] in 150 lines of code, and a prime number sieve using mailbox processors [4]. Its not possible to write any of these samples in C# in even a quarter of the lines of code.


(2) +1, I've started looking at the code while installing... I think it's going to make my head hurt more than Linq - Dead account
+1 I am reading F# on wikibooks.. - Sung
@Ian Quigley, I can confirm that! - Benjol
Not sure whether to up-vote here, for plugging ones own book (well, you wrote most of it)! :P Saying that, I skimmed over a good deal of it, and found it to be pretty well written. (Fixed one or two issues of grammar too.) - Noldorin
(5) You mean "in even four times the lines of code"? :-) - Ken
[+21] [2009-04-09 16:25:39] David Klein

I'd also recommend checking out Real World Functional Programming [1] from Tomas Petricek and Jon Skeet. (Early Access Edition already available) It covers various problems and shows how to tackle them efficiently in a functional way. Most of the Code is in F# but also in C# so you can compare which you like better/you think fits better.


(1) I've been reading this book, it is pretty good so far. - Jamie Penney
[+13] [2009-04-09 15:13:24] Tab

I won't duplicate all the great info above but I wanted to added a link to this session with Luca Bolognese. His presentation was informative, engaging and cleared up a lot of misconceptions I had about F# - certainly one of many great resources.

+1. Saw a presentation with Luca once. He's got a great accent :) - Dead account
i agree, this video was what made me look into F# in the first place :) - Alex
[+12] [2009-04-09 15:08:19] thinkhard

A good way to get into F# is to just start doing things. There are many web resources to begin learning F# from scratch. There are 3 published books on the topic as well.

Microsoft F# Developer Center [1] contains many links to get you started. A good forum for questions dealing specifically with F# is HubFS [2]

Chris Smith [3] has an excellent series on F# comparing C# implementations with their F# equivalents (dare I say betters?)

Don Syme [4], the father of F# has a weblog on the subject as well as a book out entitled Expert F# [5]

Jon Harrop [6] has a book entitled F# for Scientists [7]

Robert Pickering [8] is the author of Foundations of F# [9] with its second edition available for pre-order on, it has been renamed to Beginning F# [10] in this edition to differentiate between the other books available.

As you requested:

 printfn "hello world"

This does little to elucidate the powerful features available in the language. F# is an amalgamation of imperative, functional, and object-oriented paradigms... allowing you to smoothly transition between these approaches when crafting code. As far as I can tell F# is gaining momentum, it is slated to become a 1st class .NET language and is built into Visual Studio 2010. I run the September 2008 CTP release of F# from my windows workstations and FSharp- on linux with mono. I for one am investing a considerable precentage of my time to mastering the language.

As to why you would want to use it over C#. Thats a very good question. There are differences in the way F# compiles and C# compiles, reference some other questions on stackoverflow for good answers. I've generally noticed many naively claim that F# is simply "syntactic sugar", this is only half true.

"You obviously cannot write code in either language that compiles to the same bytecode because F# generates ILX (e.g. tail calls) and C# does not. F# also makes extensive use of CIL metadata for things that C# does not support (e.g. inlining). – Jon Harrop (Mar 14 at 7:06)"


Light syntax is now enabled by default, and I believe it's traditional for a "hello world" program to output a trailing newline, so I'd consider changing the code to just printfn "hello world". :P - bcat
[+11] [2010-06-22 12:31:06] Benjol

I just happened upon an interesting-looking online book here:

The F# Survival Guide [1]


Noted..reading that one! Thanks for the link, it looks like a REALLY good start. - Stimul8d
This Link is dead and it is impossible de find it anywhere else except into the web… - Nicolas GUILLAUME
[+6] [2010-04-24 14:32:33] Damian Powell

This might sound like a strange answer to the question "What's a good way to get into F# programming?" but stay with me!

If you want to get started with the aspects of F# that make it distinct from C# and VB, I would suggest spending some time getting to grips with Haskell - and you can even do it without reading a book! Check out Erik Meijer's C9 Lectures series on Functional Programming Fundamentals [1].

After getting about half way through, I took another look at F# (after several prior false starts) and found that the penny finally dropped. The syntax of F# made more sense after understanding a bit more about its roots. Haskell is a pure functional language with such a clean syntax that it helps in understanding the foundations without that syntax getting in the way.


totally agree about that... but I think you might even go farther and start with Scheme or LISP, i.e. reading SICP. - Kevin Won
(2) +1 Get started in F# by learning functional programming in a pure FP language. Being so easy to do imperative programming in F# gets in the way of learning the functional side of it. - Tony Lee
[+5] [2011-01-27 15:06:22] Cygwin98

The best way to learn programming is programming, a lot. Project Euler ( is a good start. To solve project euler problems, you can practice algorithms and basic data structures. To give yourself a bit more motivation, you can try to compete in some programming contests such as Google Code Jam, Facebook Hacker Cup.

Since I give my suggestions already, I think I might as well share a bit experience here.

For Project Euler problems, you really need to gradually build up your arsenals --- code snippets to do certain things, so you're not re-invent the wheels every time, which is very distracting and frustrating. For example, you may need functions to generate prime numbers, test prime numbers, generate combinations/permutations, factorization, etc. Some features I really like in F# is that bigint and BigRational, basically unlimited precision integer and rational numbers, saved me numerous times. The other advantage of F# is that you can do functional solutions first, if you need to optimize, you can evolved it into an imperative solution like what you can do in C/C++. Sometimes I do get frustrated with some features such as inflexible for loop, while loops, which makes checking loop conditions much more verbose. As there is no time constraint in Project Euler (unless you want to be the first ones to solve new problems), you can take time to think of elegant solutions. Despite of numerous complaints upon the solutions page on Haskell wiki site, I find it very helpful if I search for a better and more functional solution.

Coding competitions are totally different animals. Over there, you have to solve as many problems as possible in two or three hours. So you need to have a really good arsenal, not only data structures, but also some common algorithms, such as graph theory algorithms, dynamic programming, computational geometry, etc. As F# is relatively new and less popular language, and even less people use it in coding competition, online coding contests-related F# resource is particularly rare. Numerous time I find myself try to translate a C/C++/Java algorithm during a competition and get time expired message. That can be frustrating sometimes. So, be well prepared in advance.

[+5] [2009-12-19 20:42:34] John

For my money (free!), I am liking the The F# Survival Guide. It's a solid introduction to functional programming via F#. It lives at

[+3] [2009-04-17 09:47:35] Carsten König

I still belive Expert F# is the best publication avaiable to get into F# and it covers almost everything.

The only problem is: like every newer "learn programming" book it don't contain a single excercise - so you will need to find something to do for yourself.

I recommend starting to play with Lists, the |> operator etc. and looking at the F# Developer Center [1] (it more or less a collection of good blogs/sources and a good forum)


[+3] [2009-11-12 18:09:51] mloskot

I also recommend F# Language Overview [1] (PDF) written by Tomáš Petříček [2] It is the best F# paper I've read from short articles. Its first paragraph says:

This text is based on a short overview of the F# language (...) The goal of this article is to introduce all the features in a single (relatively short) text, which means that understanding of a few advanced topics discussed later in the text may require some additional knowledge or previous experience with functional programming.


[+2] [2009-04-10 13:37:05] flatline

Navin's post outlines the options pretty well. I'm just beginning to learn the language but can offer some reflections from my personal experience.

I couldn't get through Foundations/Beginning, it may be a good reference but it reads like a reference and glosses over too much, early on. I'm enjoying Expert F# so far, it's a much better read IMO and the later chapters have some substance to them.

If you have little or no experience with functional programming, I recommend studying the subject more generally. If you want to make full use of what F# offers, over imperative C# coding, Structure and Interpretation of Computer Programs is a classic text that goes over a lot of FP concepts (I'd recommend just watching the videos). It uses Scheme as a teaching tool but it's dead simple, the concepts are easily portable to any other language that supports functional paradigms (including C#).

For more functional programming, Project Euler is a good place to actually apply pure functional programming concepts, since they are particularly well-suited to mathematical applications. I like this site if I'm trying out the syntax of a new language, it gives you something to work on, which is often the hardest part of learning something for practical use outside of work.

[+2] [2010-09-04 14:44:52] 2sharp

A new blog with some F# tutorials is here:

[+2] [2010-04-24 14:06:40] Arif

Good Books:

* Foundations of F# (Expert's Voice in .Net) by Robert Pickering (May, 2007)
* Expert F# (Expert's Voice in .Net) by Don Syme (Dec, 2007)
* Beginning F# by Robert Pickering (coming)
* F# For Scientists by Dr Jon Harrop (Aug, 2008)
* The Definitive Guide to F# by Don Syme (coming)
* Real World Functional Programming by Tomas Petricek
* Programming F# by Chris Smith (Oct, 2009)

Please, stop that. - Will
[+1] [2010-01-29 17:14:17] Brian

Brian's favorite online content for learning F# [1]