General musings on programming languages, and Java.

Sunday, September 07, 2008

An IRC Bot in Haskell, 20% code, 80% GRR

I decided to look at Haskell more seriously, after mainly using it to learn functional programming and, well, as a posh calculator. So when I came across Don Stewart's little tutorial on writing an IRC bot, I followed it, but with one use case in mind:

In the #scala channel, often it's handy to display a URL to a bug by its index, particularly as the URLs are a little tricky to remember.

Don's code was excellent, very readable, and on my little Asus EEE, all I had to do besides install ghc6 was to install ghc6-network-dev - for some reason the Xandros packages are quite split up.

All worked fine - I tested it in a private channel, then I wanted to make it work on a remote machine, which Eugene Ciurana lets me use. Eugene is mainly a Java programmer, so he doesn't have Haskell installed at all, and as I write this, it's around 9am on a Sunday his time - I'm not going to bother him!

So I wondered about installing ghc as a user, and downloaded the 64-bit binary distribution for ghc-6.8.3. After extracting it I realised I couldn't see a bin/ directory or similar, so I checked the README file, which pointed me at the INSTALL file. So I typed ./configure --prefix=/home/ricky/ghc/, only to find out that gcc was broken on the machine.

Eugene also lets me use another machine, a 32-bit one, but on there I got this error from ./configure:

"checking for path to top of build tree... utils/pwd/pwd: /lib/i686/libc.so.6: version `GLIBC_2.3' not found (required by utils/pwd/pwd)"

dmwit and Heffalump (no, really) from #haskell suggested I try using ghc 6.8.2 instead of 6.8.3, which I am going to try shortly, but I thought of another solution. My little Asus EEE runs ghc (albeit version 6.6) well enough, so I compiled my file. After using gcc on and off for years, I was surprised that ghc 3.hs didn't do anything useful - #haskell suggested ghc --make 3.hs. This produced an executable file called 3, which I promptly ssh'd to both of Eugene's machines. On both it failed because libgmp wasn't present. So I was advised to try ghc --make 3.hs -optl-static - which seemed to almost kill my EEE. But a minute and a half later my EEE returned to its usual speed, last.fm started playing again, and I had a somewhat larger file called 3, which worked on the target machine!

So, if you wander into #scala now and type ~trac 100 it will give you a link to Scala bug report 100.

I spent more than 4 times as long on the config as I did on writing (well, mainly copying, though I copied without a clipboard) the code. Hopefully that will drop next time!

2 comments:

Unknown said...

Hello Ricky,

Sorry if I'm getting a little off-topic. I recently got myself an eeePc 2G, but I could not find the ghc6 package using synaptic. Did you have to add a special repository to get it?

Any pointers would be appreciated.

Ricky Clarkson said...

At the time I did some Googling and found that I could add some
xandros repositories to my sources.list. I think what I found came
from eeeusers.com. The upshot is, these are my /etc/apt/sources.list
right now:

deb http://xnv4.xandros.com/xs2.0/upkg-srv2 etch main contrib non-free
deb http://dccamirror.xandros.com/dccri/ dccri-3.0 main
deb http://www.geekconnection.org/ xandros4 main
deb http://download.tuxfamily.org/eeepcrepos/ p701 main etch

deb http://update.eeepc.asus.com/p701 p701 main
deb http://update.eeepc.asus.com/p701/en p701 main

I don't have the public keys of some of those repos, so dpkg gives me
warnings whenever I install anything. Also, its not exactly
satisfactory; most packages I'm interested in seem to be out of date.

I hope that helps.

Blog Archive

About Me

A salsa dancing, DJing programmer from Manchester, England.