F Sharp Programming/Getting Set Up

From Wikibooks, open books for an open world
Jump to: navigation, search
Previous: Introduction Index Next: Basic Concepts
F# : Getting Set Up


Contents

[edit] Windows

At the time of this writing, its possible to run F# code through Visual Studio, through its interactive top-level F# Interactive (fsi), and compiling from the command line. This book will assume that users will compile code through Visual Studio or F# Interactive by default, unless specifically directed to compile from the command line.

[edit] Setup Procedure

F# can integrate with existing installations of Visual Studio 2008 and is included with Visual Studio 2010. Alternatively, users can download Visual Studio Shell for free, which will provide an F# pioneer with everything she needs to get started, including interactive debugging, breakpoints, watches, Intellisense, and support for F# projects. Make sure all instances of Visual Studio and Visual Studio Shell are closed before continuing.

To get started, users should download and install the latest version of the .NET Framework from Microsoft. Afterwards, download the latest version of F# from the F# homepage on Microsoft Research, then execute the installation wizard. Users should also consider downloading and installing the F# PowerPack, which contains handy extensions to the F# core library.

After successful installation, users will notice an additional folder in their start menu, "Microsoft F# 2.0.X.X." Additionally, users will notice that an entry for "F# Projects" has been added to the project types menu in Visual Studio. From here, users can create and run new F# projects.

It is a good idea to add the executable location (e.g. c:\fsharp\bin\) to the %PATH% environment variable, so you can access the compiler and the F# interactive environment (FSI) from any location.

[edit] Testing the Install

[edit] Hello World executable

Lets create the Hello World standalone application.

Create a text file called hello.fs containing the following code:

(* filename: hello.fs *)
let _ = printf "Hello world"

Save and close the file and then compile this file:

fsc -o hello.exe hello.fs

Now you can run hello.exe to produce the expected output.

[edit] F# Interactive Environment

Open a command-line console (hit the "Start" button, click on the "Run" icon and type cmd and hit ENTER).

Type fsi and hit ENTER. You will see the interactive console:

Microsoft F# Interactive, (c) Microsoft Corporation, All Rights Reserved
F# Version 1.9.6.2, compiling for .NET Framework Version v2.0.50727
 
Please send bug reports to fsbugs@microsoft.com
For help type #help;;
 
>

We can try some basic F# variable assignment (and some basic maths).

> let x = 5;;
val x : int
 
> let y = 20;;
val y : int
 
> y + x;;
val it : int = 25

Finally we quit out of the interactive environment

> #quit;;

[edit] Misc.

[edit] Adding to the PATH Environment Variable

  1. Go to the Control Panel and choose System.
  2. The System Properties dialog will appear. Select the Advanced tab and click the "Environment Variables...".
  3. In the System Variables section, select the Path variable from the list and click the "Edit..." button.
  4. In the Edit System Variable text box append a semicolon (;) followed by the executable path (e.g. ;C:\fsharp\bin\)
  5. Click on the "OK" button
  6. Click on the "OK" button
  7. Click on the "Apply" button

Now any command-line console will check in this location when you type fsc or fsi.

[edit] UNIX

F# runs on Linux and other Unix versions with the latest Mono, although this is not officially supported by Microsoft Research.

[edit] Installing interpreter and compiler

Prebuilt packages for several distributions (.deb and .rpm files) can be found on CodePlex; upon installing these, you can use the "fsharpi" command to use the command-line interpreter, and "fsharpc" for the command-line compiler.

[edit] MonoDevelop add-in

A current Monodevelop 2.4 F# add-in with project build system, code completion, and syntax highlighting support can be installed by adding the repository in the add-in manager, then installing the F# language bindings.

[edit] Emacs mode

An emacs mode for F# is also available on SourceForge.

Previous: Introduction Index Next: Basic Concepts
Personal tools
Namespaces
Variants
Actions
Navigation
Community
Toolbox
Sister projects
Print/export