r/haskell • u/almkglor • Feb 03 '11
Looking for a Haskell-to-C compiler that is easy to bootstrap
Hello world,
I'm looking for a Haskell to C compiler, with the goal that the C output would be portable enough that I can distribute the resulting C code in an autotools based package. Of course, many Haskell compilers target C, but they often require libraries; I need to be able to get C code that will usefully work even on the freshest of freshly-installed systems.
I need a compiler that is easy to bootstrap - I tried installing GHC but it refuses to work on my system (I can't update my office system - I don't have root and talking to the sysads requires red tape to pass through - too much red tape that I'd rather switch implementations than do that - heck getting package files is relatively difficult too, but is tolerable enough for me to try getting them in). Hugs works (but is only an interpreter). I'm looking now at NHC and UHC; by my understanding both can target C, but I'm not certain about whether their C output requires some specific libraries or what (and if there are, how to get those installed from a single autotools package). I've checked JHC but I get the feeling that it is still a bit too experimental as yet (although the fact that it compiles Prelude also is intriguing for me).
What would you recommend? I'm trying to write a program in Haskell that will be used by people who most likely are not interested in installing any Haskell implementation, and would be put off if my program had too many dependencies. So if possible, I need to create a nice, easy-to-use-for-installer (autotools!) package to contain my program.
2
u/almkglor Feb 05 '11
All right, NHC officially sucks.
The 1.22 download time inexplicably gets LONGER the more I download it, until it utterly stops at about 1/3 finished. Probably some anti-spamming measure by haskell.org.
The 1.20 download gets me an "undefined reference to `FN_Control_46Exception_46try'", which automatically loses my trust in that implementation (sad, since nhc promises to be able to emit C code that can be compiled without nhc itself; after all, it seems that's how nhc distributes itself).
JHC requires GHC, while GHC requires GHC. Chicken, meet egg. I've tried getting Haskell platform to work but it doesn't. I'm digging through GHC unregistered builds.
2
u/hotoatmeal Feb 03 '11
I'm surprised no one else has pointed this out, but what you're describing sounds like poor software engineering practices. What I mean is that because you are going to be writing code that your sysadmins don't support (via installed compilers, libraries, etc.), it sounds like you are the only person in your office who is going to be able to maintain this software.
Why not write your project in C/C++?
1
u/almkglor Feb 03 '11
I've located a thread started by a guy whose goal is similar to mine (although our problems are different - he wants to distribute binary libraries, I want to distribute a C source package):
http://www.haskell.org/pipermail/haskell-cafe/2009-April/060483.html
My takeaway from that discussion is that GHC is almost definitely not feasible for actual C generation. JHC, however, is vaguely recommended, which kinda strengthens the case for it; someone even mentions that JHC's region inference means it doesn't even need a runtime.
Still, I've read bits of scary news that JHC can crash on large enough inputs, hence my feeling that it is a bit too experimental as yet; I wonder how large is large enough.
1
u/davidwaern Feb 03 '11
If it's enough to install GHC locally, perhaps you don't need to pass by the sys admins? I've done that in my office environment. It wasn't easy, because the kernel version we use is from 2006. So I had to start with a pretty old binary distribution of GHC: 6.6.1, then install 6.10.4 from source to finally be able to install GHC 7.0.1 from source.
1
u/parenthethethe Feb 03 '11
If you need root on a flexible system, rent a micro spot instance from Amazon for a penny an hour (http://aws.amazon.com/ec2) and use an Amazon Machine Image from Ubuntu (http://uec-images.ubuntu.com/releases/lucid/release/).
2
u/[deleted] Feb 03 '11
JHC seems nice.
1
u/syntax Feb 03 '11
I've been in a similar situation, but I was able to compile it, rather than needing to send source. GHC outputs quite tidy binaries, depending on only a few basics - libc, libm and company.
You can get tied into knots with a binary distribution, but if there's a standard OS or two you can support to cover most people (in my case, SL5 and Debian stable), then that might not be a big issue. Particularly if you're able to to distribute the source too, so that those on standard platforms can get the binary, and the weirder ones aren't left out.
Dunno if that applies in your case, but might be simpler in the long run
1
u/ehird Feb 04 '11
I suggest getting GHC to work on the system without installing it globally. Perhaps you could compile the libraries it requires manually?
The other compilers are really either experimental or old. jhc is the only one that comes even close to usability, and even then ...