[Haskell-cafe] Compiling a DSL on the shoulders of GHC

Patai Gergely patai_gergely at fastmail.fm
Sun Oct 17 13:53:42 EDT 2010


Hello all,

I'm trying to reuse as much of the sweat and tear put into GHC as
possible to derive a compiler for a language highly similar to Haskell
in many aspects. The difference is that instead of constructing an
expression of type IO (), the programmer has to provide a stream
processor on the top level - whether this is an arrow structure or just
a pure function mapping input to output is not decided yet. In other
words, I want to allow the programmer to use full Haskell as a
metaprogramming language to create an expression of a much more limited
language.

My idea was to move the relevant types into a module, and make my
combinators simple data constructors behind the scene, so the Haskell
phase would effectively build an AST. The tricky bit is that I don't
necessarily want to make everything an explicit data constructor. For
instance, I'd like to allow Haskell functions in the tree.

Using the GHC API, I can get the Core representation of the metaprogram.
What I'd like at this point is to evaluate the top level expression and
still have a representation open to analysis (traversal, pretty
printing, interpretation etc.), including lambdas; if this evaluation
takes more time than some well-defined limit, I could treat it as a
compile-time error. Basically, I want the constant that is the main
program to be folded completely if possible during compile time, and
signal an error in case it isn't or doesn't seem to be. The resulting
structure would be transformed further by a separate application instead
of the existing GHC backends.

Unfortunately the GHC API is not very approachable for the uninitiated,
so it's not clear to me whether this is even possible. Or is it simply
such a bad idea that it's not even worth considering in the face of more
conventional approaches?

Gergely

-- 
http://www.fastmail.fm - Same, same, but different...



More information about the Haskell-Cafe mailing list