Sublime Text & Haskell

There are several excellent posts about setting up the Haskell development environment. One of the best ones is Tony Lawrence’s Configuring Your Haskell Environment. I encourage you to take a look at his post first.

Tony’s post is more than a year old though, and it looks like a couple of things have changed since he wrote his post, especially with the latest version of Haskell and SublimeHaskell. I wasted a good chunk of time trying to get around those problems, so now writing this post in case others run into similar issues when setting up the SublimeHaskell plugin.

Here’s a summary of the steps to setup the Haskell dev environment (from Tony’s blog).

This last step doesn’t work seamlessly. When I installed SublimeHaskell, I ran into the following error message in Sublime Text:

SublimeHaskell: Failed to compile ModuleInspector

/Users/umair/Library/Application Support/Sublime Text 3/Packages/SublimeHaskell/ModuleInspector.hs:141:12:
    Not in scope: data constructor ‘H.PNeg’
    Perhaps you meant ‘H.PRec’ (imported from Language.Haskell.Exts)

The problem is described in more detail in issue #182 on SublimeHaskell’s GitHub page. The summary is that the master branch of SublimeHaskell is too slow to accomodate the removal of PNeg from haskell-src-exts. The solution is to use the hsdev branch of SublimeHaskell. This is done as follows (recommended by MoreAxes on comment thread for issue #182):

  • In Sublime Text, launch Package Control (cmd-shift-p), and use the ‘Add Repository’ command to add https://github.com/SublimeHaskell/SublimeHaskell/tree/hsdev.
  • Install SublimeHaskell with Package Control normally. Package Control looks in user-defined repositories first, so it is able to get SublimeHaskell from the hsdev branch.
  • Restart Sublime Text.

You can now enter and build Haskell code from Sublime Text. To verify your setup, enter the following code in Sublime Text, and then hit cmd-B

main :: IO()
main = do
    print "Hello World"

You will see the following printed:

"Hello World"
[Finished in 0.2s]

Here’s a screenshot of my test file, with the output of the program:

Haskell in Sublime Text