[Haskell-cafe] adding recursion to a DSL

Edsko de Vries edskodevries at gmail.com
Tue Feb 19 11:14:02 CET 2013


Hi Joerg,

You might find "Abstract Syntax Graphs for Domain Specific Languages" by
Bruno Oliveira and Andres Löh (
http://ropas.snu.ac.kr/~bruno/papers/ASGDSL.pdf) a helpful reference to
adding things like recursion (and other binding constructs) to your DSL.

Edsko


On Tue, Feb 19, 2013 at 9:47 AM, Emil Axelsson <emax at chalmers.se> wrote:

> You probably don't need recursion in the DSL for this (that would require
> a way to detect cycles in the expressions). For this example, it looks like
> all you need is to add something like `map` as a DSL construct.
>
> Your example could perhaps be expressed as
>
>   forEach (1,1000) (\n -> out (matrixMult, A, n, row, matrix-row))
>
> For this you need a way to reify functions in the DSL. For an example of
> how to do this, see the `While` and `Arr` constructs in this paper:
>
>   http://www.cse.chalmers.se/~**emax/documents/**
> svenningsson2013combining.pdf<http://www.cse.chalmers.se/~emax/documents/svenningsson2013combining.pdf>
>
> I'm not familiar with your particular DSL though, so I might have missed
> something.
>
> / Emil
>
> 2013-02-17 23:53, fritsch at joerg.cc skrev:
>
>> I have a tiny DSL that actually works quite well. When I say
>>
>> import language.CWMWL
>>
>> main = runCWMWL $ do
>>      out (matrixMult, A, 1, row, matrix-row)
>>
>> then runCWMWL is a function that is exported by language.CWMWL. This
>> parses the experession and takes some action.
>>
>> Now, A is the name of the matrix and the third tuple element would
>> represent the numbe of the row. For example 1 to 10000. I want to achieve
>> some sort of "elegant" (means readable code, a good representation)
>> recursion that would let me do something like
>>     sequence [ out (matrixMult, A, n, row, matrix-row) | n <- [1..1000] ]
>> but in a nicer manner an without expending this to 10000 lines of code at
>> compile time.
>>
>> How can I best introduce recursion into my DSL or borrow this from the
>> host language Haskell "effectively"?
>>
>> --Joerg
>>
>>
>>
>> ______________________________**_________________
>> Haskell-Cafe mailing list
>> Haskell-Cafe at haskell.org
>> http://www.haskell.org/**mailman/listinfo/haskell-cafe<http://www.haskell.org/mailman/listinfo/haskell-cafe>
>>
>>
> ______________________________**_________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/**mailman/listinfo/haskell-cafe<http://www.haskell.org/mailman/listinfo/haskell-cafe>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130219/bf2111fc/attachment.htm>


More information about the Haskell-Cafe mailing list