Friday, January 29, 2010

Getting started with Haskell in Eclipse

If you just want to play around with Haskell a little, you can quickly get started by just installing GHC and using a basic text editor. But what if you, like me, tend to put everything neatly into some Eclipse workspace? Well, here's what you need.

(I'm describing this for the Mac. Windows users will need some imagination ;-)

Install the Haskell Platform

First, you need the basic Haskell platform, consisting of GHC, the Haskell compiler, and the standard libraries. You can download the platform from http://hackage.haskell.org/platform/ It comes with a neat installer and brings pretty much everything required to get started.

Get the Eclipse Plug-In

EclipseFP, the plug-in that provides Haskell development support in Eclipse, can be installed from its update site at http://eclipsefp.sf.net/updates. Choose version 1.109.0.

(Sentimental note: EclipseFP is already a seasoned project, and I'm delighted to see that it is still alive and kicking. After Thomas ten Cate worked on it during a Google SoC project last year, it has been maintained and advanced now for some time by J.P. Moresmau. And there's some cool stuff in it now indeed :-)


Build the scion server

In order to function properly, EclipseFP requires an installation of Scion on your computer. Scion is a Haskell library that provides common functionality for Haskell development tools and is used in a number of editors and IDEs.

This is the part where it gets interesting, since you have to build scion from source. (EclipseFP needs some of its features that are not yet in the officially released version.) Here's how you do it:

Seneca:~ leif$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 6.10.4
Seneca:~ leif$ git clone git://github.com/JPMoresmau/scion.git
[skipping output]
Seneca:~ leif$ cd scion/

Seneca:scion leif$ cabal install
[skipping output]
Seneca:scion leif$

You need git (the distributed source control system) to get a copy (a 'clone' in git speak) of the scion repository. Then you run Cabal (the common Haskell build tool) to compile and register scion. The commands I've pasted above should to the trick for you.


Tell EclipseFP where to find the scion server

Finally, the Eclipse plug-in has to know where to find the executable of the scion server. Run Eclipse and open the Preferences at Haskell > Scion. Click 'Autodetect'. For me, this resulted in EclipseFP locating the server executable correctly and putting it into the text field.

You can verify that EclipseFP works correctly by simply creating a new Haskell project in the workspace. The wizard conveniently generates a 'Hello world'-like program with a Main module. Open it in the editor: if you see an outline, and if you get syntax errors when you type in some bogus code, then you know that EclipseFP has everything it needs.

That's it — have fun :-)

1 comment:

  1. Thanks for your instructions!

    However, using the Git repository mentioned above did not work for me. Instead

    git clone git://github.com/nominolo/scion.git

    as mentioned on the scion-lib project page did work.

    ReplyDelete