My love of functional programming has been getting stronger over the past year so I decided to attend Well-Typed Haskell courses at Skills Matters1. As I’m a huge fan of JetBrains IntelliJ IDE I found using Haskell a little lacking in this area (unless you can be online with FP Complete.)
In this article I will explain how I configured my Haskell development environment using Sublime Text 3 and a few extras.
Installing Haskell (via Homebrew2)
If you need to, take a look at my post on how to Install Homebrew. It’s not actually very hard at all.
Once you have Homebrew up and running it’s very simple to install Haskell (although it might take a while to complete.)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
As requested I also run
cabal update to initialise the package list.
1 2 3 4 5
Then check that it’s all working correctly.
1 2 3 4 5 6 7 8 9 10 11
Installing Sublime Text 3
Sublime Text 3 is currently still in beta. I have been using it for a while and have not come across any problems which is why I can highly recommend giving it a go. It can be downloaded from http://www.sublimetext.com/3. Once downloaded, open the DMG file and copy to your Applications folder. On starting you will be greeted with the following:
If you like sublime please purchase a license to allow the developers to keep supporting this great application3.
Configuring Sublime Text for Haskell
To allow us to fully use the power of Sublime Text we need to install Package Control. This will allow us to use the Haskell package later. Full instructions on installation can be found on the Package Control Site. A quick overview follows.
Installing the Package Control
Whilst in Sublime Text type
ctrl+` to open up the console and paste the following:
The output in the console will probably look something like this:
1 2 3
If you don’t want to trust the script you can follow the manual instructions on the package control website.
Installing SublimeHaskell Package
SublimeHaskell4 is a github hosted project which adds support for many things. I mainly use it to auto-compile the edited file on save and easily running a Haskell program from the editor. Full instructions are available at the SublimeHaskell project site. Below I will show how I got everything working.
There are a few packages that need to be installed for this package to work. Using
cabal makes this easy (although it might take a while.
Now, to install the package in Sublime Text 3 you can type
cmd-shift-P to open up the search window. Type in
install to locate the install package option and select it. You should see in the status bar that it is going to the repository to find available packages.
Next type in
haskell to locate the SublimeHaskell package and select it.
The status bar should indicate that it is installing the package and when it is completed. Lastly we need to configure the package to use hdevtools as this isn’t the default behaviour.
From the menu choose
Package Settings –>
Settings - User to open up the user settings. Now paste the following into that file and save making sure you replace
<username> with your username.
1 2 3 4 5
A restart is then required.
You can now enter your Haskell code into Sublime Text, make sure you have the Haskell build system selected and then type
cmd-B to save, build and execute the code!