F Sharp Programming/Getting Set Up
From Wikibooks, the open-content textbooks collection
| 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 2005 and Visual Studio 2008. 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. Afterward, download the latest version of F# from the F# homepage on Microsoft Research, then execute the installation wizard.
After successful installation, users will notice an additional folder in their start menu, "Microsoft F# 1.9.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
- Go to the Control Panel and choose System.
- The System Properties dialog will appear. Select the Advanced tab and click the "Environment Variables...".
- In the System Variables section, select the Path variable from the list and click the "Edit..." button.
- In the Edit System Variable text box append a semicolon (;) followed by the executable path (e.g.
;C:\fsharp\bin\) - Click on the "OK" button
- Click on the "OK" button
- 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 unices with the latest Mono, although this is not officially supported by Microsoft Research. The installation has been documented, and consists of obtaining Mono, downloading the F# release, registering its DLLs with gacutil, and writing wrapper shell scripts that call fsi.exe and other executables with the Mono runtime, for example:
/usr/bin/fsc: #!/bin/sh mono /opt/fsharp/bin/fsc.exe $*
In the UNIX world there are many development environments, but few of them support F#, as it is often mistakenly regarded as a Windows-only language. Nonetheless, there is an alpha quality MonoDevelop F# plugin. Also, one can get a great deal of support from OCaml environments, such as Emacs with caml-mode or tuareg-mode. For Emacs, there is also an F# mode.