[Haskell-cafe] Consequences of implementing a library in Haskell for C consumption?

Austin Seipp mad.one at gmail.com
Thu Sep 4 21:04:25 EDT 2008

Excerpts from Justin Bailey's message of Thu Sep 04 17:00:58 -0500 2008:

> Looking at the package, I think would be pretty painful though. It
> seems I'd have to build the AST by hand,

The AST Language.C defines for C is actually fairly regular once you
wrap your head around it - I got it to generate working programs that
I could compile in approximately an hour after looking through nothing
but the documentation, essentially.

The AST is very 'raw' though: I found that defining some simple
functions for things like just creating a global variable, creating
declarations and the like cut down on overall AST size tremendously
(although hints of the AST types/constructors were still around, naturally.)

Here's the example I put on HPaste a few days ago:


You'll notice that the actual shim you're looking at - with the help
of the defined functions - is actually fairly small, and those
functions help out with those *a lot.* That was the first thing I
wrote with it though, so the functions could probably be further
generalized and abstracted.

On that note (although a little OT,) does anybody think it would be
nice to have a higher level library designed specifically around
emitting C that uses Language.C? A lot of repetetive stuff can be cut
down considerably, I think.


More information about the Haskell-Cafe mailing list