[Haskell-cafe] A question on DSL's

John Van Enk vanenkj at gmail.com
Mon Jan 4 12:21:06 EST 2010


To start with, can you clarify that you are looking for an Embedded DSL
(sometimes called Light Weight DSL)?

A _proper_ DSL has its own interpreter/compiler where an EDSL/LwDSL
leverages the compiler of a host language (in this case, Haskell).

Assuming you're referring to an EDSL, I'll respond. :)

I don't think the second option is ever used. Modifying the compiler backend
doesn't seem to make a lot of sense to me. I'm not aware of any circumstance
where this has been done.

Your first option is closer. Generally, when emitting some sort of target
code from a large EDSL, you'll have two stages. Your first takes the
embedded syntax of your EDSL and converts it to an Abstract Syntax Tree.
Your second stage accepts the AST as input and emits target code.

Take Tom Hawkins' Atom EDSL as an example. When we write Atom code, we're
building up an AST. After the AST is built up, the "compile" function
converts the AST to C code.

For smaller EDSLs, it's more than possible to have the functions themselves
emit the code we're after (rather than relying on an AST and compile
function).

Is this what you're looking for?

/jve

On Mon, Jan 4, 2010 at 12:14 PM, CK Kashyap <ck_kashyap at yahoo.com> wrote:

> Hi,
> I am not sure if I'm using DSL in the right context here but I am referring
> to those solutions that allow us to write code in Haskell and generate a
> target code source code of another language or even object code for that
> matter. I am aware of two ways of achieving this -
> 1. Implement functions that emit the target code - that is, when the
> Haskell code is compiled and run, the target code is emitted
> 2. Modify the Haskell compiler's back end to emit the code - that is when
> the Haskell code is compiled the target code is emitted
>
> I am not sure if there are more ways (hybrid perhaps) ...
>
> My question is,  when would I chose one approach over the other?
>
> Regards,
> Kashyap
>
>
>
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100104/60c1c2b8/attachment.html


More information about the Haskell-Cafe mailing list