F Sharp Programming/Getting Set Up

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.

Setup Procedure
F# is included with Visual Studio 2019. Alternatively, users can download Visual Studio Express or Community for free, which will provide an F# pioneer with everything one 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.

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. ) to the   environment variable, so you can access the compiler and the F# interactive environment (FSI) from any location.

As of Visual Studio 2019 the easiest way to get going is to install Visual Studio 2019 for Web at (even if you want to do desktop solution). You can then select F# language support from within the installer. Once this is done you can create F# projects. Search Nuget for additional F# project types.

Hello World executable
Lets create the Hello World standalone application.

Create a text file called  containing the following code:

The underscore is used as a variable name when you are not interested in the value. All functions in F# return a value even if the main reason for calling the function is a side effect.

Save and close the file and then compile this file:

fsc -o hello.exe hello.fs

Now you can run  to produce the expected output.

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

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

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

Finally we quit out of the interactive environment

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.  )
 * 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  or.

Mac OSX, Linux and UNIX
F# runs on Mac OSX, Linux and other Unix versions with the latest Mono. This is supported by the F# community group called the F# Software Foundation.

Installing interpreter and compiler
The F# Software Foundation give latest instructions on getting started with F# on Linux and Mac. Once built and/or installed, you can use the "fsharpi" command to use the command-line interpreter, and "fsharpc" for the command-line compiler.

MonoDevelop add-in
The F# Software Foundation also give instructions for installing the Monodevelop support for F#. This comes with project build system, code completion, and syntax highlighting support.

Emacs mode and other editors
The F# Software Foundation also give instructions for using F# with other editors. An emacs mode for F# is also available on Github.

Xamarin Studio for Mac OSX and Windows
F# runs on Mac OSX and Windows with the latest Xamarin Studio. This is supported by Microsoft. Xamarin Studio is an IDE for developing cross-platform phone apps, but it runs on Mac OSX and implements F# with an interactive shell.