[Haskell-cafe] adding recursion to a DSL

Emil Axelsson emax at chalmers.se
Tue Feb 19 10:47:29 CET 2013


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

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
>



More information about the Haskell-Cafe mailing list