[Haskell-cafe] compilation to C, not via-C

wren ng thornton wren at freegeek.org
Fri Apr 24 20:00:26 EDT 2009


Sam Martin wrote:
> In short, I'd like to use Haskell as a code-generator.
> 
> I can't see that this would be unachievable, particularly given it's
> generating C already. Have I missed something?

For the case of GHC at least, you may be. The "C" that GHC compiles 
Haskell into isn't C in the normal linguistic sense, but rather C as a 
syntax for portable assembly. The GHC runtime is an STG-machine, so the 
"C" code for a program is really just declarations of the language of 
thunks and closures for the STG to do graph reduction on.

I seem to recall that there are other Haskell compilers which make more 
of an effort to target C as an output language (rather than targeting 
portable assembly), though I haven't tried them myself.

-- 
Live well,
~wren


More information about the Haskell-Cafe mailing list