Friday, 4 May 2012

Getting started with F#

A lot of great F# content is being deleted from Stack Overflow including this excellent answer by Brian McNamara of the F# team to the question "How do I get started with F#" so we'll keep a copy here:

Entry point is here -> Microsoft F# Developer Center

For a quick taste, consider trying F# in your browser.
Start by watching videos and presentations (BTW, An Introduction to Microsoft F# 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 by Chris Smith
  2. Expert F# 2.0 (Expert's Voice in F#) by Don Syme, Adam Granicz, and Antonio Cisternino
And in addition to that:

Quick Links:




Good Books:


Hello World Samples:

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, linked from the F# download page), or the VS2010 integrated shell (free download). 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. The F# compiler and fsi.exe are now part of the Mono distribution.

1 comment:

Benjol said...
This comment has been removed by the author.