F# Getting started…

After attending a presentation on F# tonight it made me want to learn more about the language. So in this post i’m going to outline the first steps in getting F# setup and running in Visual Studio 2008, and also do a simple hello world f# project.

Installing F#

  1. Close any open instances of visual studio.
  2. Download F# for VS.NET 2008
  3. Follow through the wizard, accept the terms and click Install. It takes a few minutes for it to finish, once it’s done click Finish.

Creating New F# Project

  1. Open Visual Studio 2008.
  2. Select File -> New Project
  3. You should now see F# Projects as an available project template. Choose F# Application, give it a clever name like “FSharpSample” and click OK.
  4. Copy the code below into your program.fs file. Note that I’ve commented each line in order to help you better understand what’s going on.

    // Same as "Using System"
    open System
    // Syntax for attributes in F# is [<>]
    // EntryPoint marks it as the entry point for console applications
    // This is how you define a function or method.
    // let [method name] [parameters (space seperated) =
    let main args =
    printfn "Hello World of F#!" // Same as Console.WriteLine
    // Note that this is wrapped in ignore(). Any method that returns a value in F# that you don't want to use
    // you have to wrap it in this method.
    ignore(Console.ReadKey());
    // Always return integer for main entry point in console application.
    0
  5. Hit F5 and if all is well you should see a console window that says “Hello World of F#!”.

If you have never seen F# before and are using to C# or VB.NET, then the syntax will probably throw you off, but that is how it is with any new language. To expand on what was covered in this post, I’d suggest going to fsharp.net and reading through the documentation and downloading some samples from there.

F# is a functional programming language and if you don’t know what that is here’s the wikipedia:
http://en.wikipedia.org/wiki/Functional_programming

Best of luck! I hope this got you going if you were interested in F# and looking to get started using it in Visual Studio 2008.

Matti