Monday, 26 August 2013

How to: Setup F# Development Environment in Mac

F# has been an awesome programming language, it gives a simple and elegant way to code, review and iterate. Despite F# is a open source project, it still could not get rid of the Microsoft gene underneath its skin. 

While just like C#, I am not against it at all, but really enjoy and has been working with C# for a long time. It is the hassle to utilise and migrate to different platforms irritates me.

This time, Mono has come to our rescue to help us hack on Mac.

1. Install Mono MRE and MDK

In order to able to compile and run F# using Mono, MRE (aka. Mono Runtime Environment) and MDK (aka. Mono Development Kit) need to be installed. Visit the link to the official site to get the latest version.

After installation, you should be able to navigate to 

/Library/Frameworks/Mono.framework/Versions/
to check the version you installed. Most importantly, make sure the 'Current' version under the directory points to the correct version you want.

2. Install MonoDevelop (aka Xamarin Studio)

From the previous Mono download, you should be able to find the link to MonoDevelop as well. In case you could not find it, take the express bus to the site to rock.

3. Install F# Compiler

Head over to fshaper's GitHub page to get an instruction on how to make sure of the compiler. For Mac users, I have also listed out some steps from the page just to keep this introduction neat.

Before we proceed, you probably would like to check if you have got brew and Xcode command line tools installed.

Brew is an open source project to help you manage packages on Mac, an equivalent to apt-get or Chocolatey if you like. The installation is just to execute the following line in terminal.

ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
Xcode command line tools is something could easily be forgotten, but it can be found and installed very fast from the following location in Xcode.

Preferences -> Download -> Command Line Tools
Now we need to make use of them in assist of getting our fsharp complier up and running. In your terminal, run the following command in sequence.

#Install Automake to help build the compiler
brew install automake

#Navigate to your desiable localtion, and get a copy of fsharp project
git clone git://github.com/fsharp/fsharp.git

#Navigate into the fsharp project
cd fsharp

#Execute autogen script pointing at the current version of Mono
./autogen.sh --prefix=/Library/Frameworks/Mono.framework/Versions/Current/

#Compile fsharp compiler code
make

#Install fsharp compiler
sudo make install

To verify fsharp compiler has been installed successfully on your Mac, run the command below, and you should get the result as well.

fsharpc

F# Compiler for F# 3.0 (Open Source Edition)
Freely distributed under the Apache 2.0 Open Source License

error FS0207: No inputs specified

4. Install MonoDevelop F# Binding

To get your Xamarin Studio displays F# along with other standard languages, we need to sort out the language binding. In order to do that, execute the following commands.

#Navigate to your desiable localtion, and get a copy of fsharp binding project
git clone git://github.com/fsharp/fsharpbinding.git

#Navigate into the fsharp binding project
cd fsharpbinding/monodevelop

#Execute configure script
./configure.sh

#Compile fsharp binding code
make

#Install fsharp binding to MonoDevelop
sudo make install

5. Enable F# Binding in MonoDevelop

We are almost there, but don't get to exited just yet. The last thing we need to do is to make Xamarin Studio display the F# option, you should be able to enable the configuration under this location by installing it.

Xamarin Studio -> Add-in Manager -> Installed -> Language bindings -> F# Language Binding
Now if you go create a new solution, you can then see the magnificent screen!