# Getting started with using SublimeHaskell and Cabal

I recently started using Sublime Text 2 as my main editor for non .net related languages – and I really enjoy it (I think I will pay Mr. Skinner soon – well deserved!).

If you are working with Haskell, then there is a rather good plugin named SublimeHaskell you can use to get automatic compile-error reporting (on save) and an integrated type query and type insert mechanism I quite like.

But in order to get this you have to set up your Haskell project with cabal and install the plugin first.

The installation itself is very simple once you installed the “Package Control” for Sublime Text 2 (see the link – it’s basically nothing more than running the following snippet inside the Sublime Text 2 console).

import urllib2,os;
pf='Package Control.sublime-package';
ipp=sublime.installed_packages_path();
os.makedirs(ipp) if not os.path.exists(ipp) else None;
urllib2.install_opener(urllib2.build_opener(urllib2.ProxyHandler()));
print 'Please restart Sublime Text to finish installation'



With the Package Control ready you just have to use the package-install, search for SublimeHaskell and hit return – done.

# Setup a basic Haskell Cabal project

Create a folder for your project and create your Haskell source file(s) – here I’m using a very basic one:

-- Greetings.hs
-- Copyright (c) 2012 Carsten König
--

module Greetings where
import System.Environment

main :: IO ()
main = getArgs >>= print . greetings . head

greetings s = "Hello! " ++ s



Next create a .cabal file for your project – this is where you tell Cabal how to build/install your files and what dependencies it has, etc.(see the Cabal user guide for additional information):

Name:                greetings
Version:             0.0
Description:         say Hi
Author:              Carsten König
Maintainer:          Carsten@gettingsharper.de
Build-Type:          Simple
Cabal-Version:       >=1.2

Executable greetings
Main-is:           greetings.hs
Build-Depends:     base >= 3 && < 5
&#91;/sourcecode&#93;
</pre>
</div>
<p>Important are the name (which names your package), Executable &lt;name&gt; (the –o(utput) name) and Main-is entry.</p>
<p>Finally you will need a (very basic) Setup.hs script for cabal:</p>

import Distribution.Simple
main = defaultMain



That’s it – now you can install/build your project with Cabal like this:

cabal install --prefix=$HOME--user  Please note:$HOME is where cabal should write your binary output to – it will create/use a “bin”-folder right below \$HOME.

That’s it – now whenever you save your file in SublimeText it ghc will run it and possible errors will show like this:

And even better: if you mapped your keybindings in the “Preferences/Key Bindings – User” settings of Sublime Text like this:

    {
"keys": ["ctrl+k", "ctrl+h", "ctrl+t"]
},
{