I would like to use haskell to translate my DSL to R
I would like to use haskell to translate my DSL to R. I mean I want to parse my DSL first and then generate R code from it. I know haskell implements DSLs, but they all assume the target DSL compilation language is haskell code.
Please note that the final product must be generated by R-code. So it's not just a DSL implemented in haskell, but a DSL that generates non-haskell code; in my case R-code.
The pseudocode for DSL might look like:
d =_ a o b o c
# ==>
d <- function(x) a( b( c( x))) # generated R code
f1 a b =_ a + b
# ==>
f1 <- function(a, b) a + b # generated R code
f2 =_ \x. a (\y. y + y) (x * x) (\z. z / z)
# ==>
f2 <- function(x) a( function(y) y + y, x * x, function(z) z / z) # generated R code
put_ "abc " "def"
# ==>
print(put("abc ", "def ", sep="")) # generated R code
You need to write a small compiler that will read your DSL files and generate R code. There are several compilers you can look at to figure out how to write them.
Haskell to C: Jhc ( AJHC ), Copilot
Haskell for JS: Fay , Roy
There are also compilers for hardware languages. I would recommend taking a look at Fay for links