Imprisoned by the Haskell Toolchain

Posted on January 6, 2013 by Jack Kelly
Tags: coding, rants

I was going to write a new version of metscrape in C that supported plugins, so people could contribute modules for their local weather services. C is still one of the best ways to go for portable programs, and a plugin system means you don’t need to build in support for unused countries.

But.

I wanted to write my plugins in Haskell, mainly because HXT is peerless when it comes to slicing and dicing XML.

So.

The Haskell FFI is pretty good. Actually, it’s one of the best I’ve used: you declare functions “foreign export” and can fiddle around with things, preserve objects from the garbage collector and so on.

However.

The toolchain support is terrible. Basically, it wraps gcc: if you want to compile a mixed Haskell/C library (and you probably do, to expose the correct entry points, call hs_init() or other low-level details), you have to compile your .c files with ghc. Which means it won’t play nice with automake or anything else that wants to use dependency tracking via -M or -MM. automake will want to invoke $(CC) to compile C files, possibly through libtool if you’re building a shared library or module. Further, the link command doesn’t even put in all the libraries that it needs, so you have to add them yourself.

Modern GHC supports shared libraries, but debian doesn’t ship them, so you can’t rely on the dynamic linker to sort it out for you.

There’s no command akin to pkg-config to give you the right cflags/ldflags to pass to the compiler.

So basically you can’t get proper dependency tracking or anything. Ugh. Have fun reimplementing all the required features in the GNU Makefile Standards.

The ultimate problem is that people insist on rolling their own sucky versions of build systems and package managers. (Though cabal and ghc --make suck less than most, I’ll admit).

Lessons.

When I passed around a draft of this post, one reviewer asked me if I seriously expected compiler writers to learn autotools to play nice with it? My answer is a resounding YES. The autotools aren’t that hard to learn, and there’s a fantastic tutorial to learn from. If you’re smart enough to write a compiler, you’re smart enough to learn how to make it play nice with the rest of the world.

Previous Post
All Posts | RSS | Atom
Next Post
Copyright © 2021 Jack Kelly
Site generated by Hakyll (source)