Fsharp On Mac FSharp

Apr 20th, 2016 - written by Kimserey with .

Yesterday, a friend of mine asked me what was the easiest way to get started with F# on Mac. I pointed him to http://fsharp.org/use/mac/ which gives multiple options to install F# on Mac but it doesn’t contain the option of using VSCode with Ionide. Since I think it is the most straight forward way to have an environment setup to use of F# rapidly especially when someone wants to just have a quick look, I decide to write a blog post to go through the installation step by step.

The steps are:

  1. Install brew
  2. Install mono from brew
  3. Install VSCode
  4. Install Ionide
  5. Write a .fsx script

1. Install brew

http://brew.sh/

To install brew, start a terminal and paste the following:

1
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

brew

Homebrew is a package manager. We will use it to install mono. After executing the command, you should have access to brew from the terminal.

2. Install mono

Mono is an open source implementation of Microsoft’s .NET Framework

To install mono, start a terminal and paste the following:

1
brew install mono

mono

After you installed mono, you should have access to fsharpi. fsharpi is the fsharp interactive also called FSI.

fsi

3. Install VSCode

https://code.visualstudio.com/

Install Visual studio code https://code.visualstudio.com/. Visual studio code is a code editor which also allows developpers to write plugins against it. Thanks to the amazing work of @k_cieslak, we can use F# with VSCode using Ionide. Ionide is a package suite which provides interaction with FSI, autocompletion, syntax highlighting and many more amazing things.

4. Install Ionide

http://ionide.io/

If we go to the Visual studio marketplace and look for Ionide, we should be able to find ionide-fsharp https://marketplace.visualstudio.com/items?itemName=Ionide.Ionide-fsharp

Below Installation, the website gives us an indication on how to install the packge on VSCode.

1
2
3
Launch VS Code Quick Open (⌘+P), paste the following command, and type enter.

ext install Ionide-fsharp

ionide

That’s it, you have all the necessary tools to write code in F# now.

5. Write a .fsx script

Now that you have all the stuff needed. Create a .fsx file and paste the following:

1
2
3
4
let helloWorld =
    "Hello world from FSI"

printfn helloWorld

Select the whole text and hit ALT + ENTER. If everything is alright, this command will execute the highlighted code in the FSI.

fsi_code

Conclusion

Today we saw a quick way to get started with F# scripts. As a starter I would suggest to look at an example from @ScottWlaschin website https://fsharpforfunandprofit.com/. Have a look at the tic tac toe example. Coming from an OOP language, it was really helpful for me. If you have any issue, please let me know here or hit me on Twitter @Kimserey_Lam!

Designed, built and maintained by Kimserey Lam.