
On 11/24/2010 03:14, jean-christophe mincke wrote:
Hello,
I am still playing with template-haskell...
I wonder, is there any reason why a quasiquoter cannot create haskell statements and declarations in addition to expressions and patterns? Or more generally create any legal Haskell syntax tree.
In GHC 7, quasiquotes can appear in place of expressions, patterns, types and top-level declarations. The latter two are new (see [1]).
I.e Suppose I would like to create a quasiquoter for the C language (please, imagine that it could be useful).
It is useful, and it already exists [2] :)
I could write sth such as :
[$c|
int a = 6; int b = 7; int c = a +b;
struct S { int x; int y} |]
It could be nice to generate the appropriate haskell code:
a = 6 b= 7 c= a + b data S = S { x::Int; y:Int} etc
language-c-quote doesn't translate C to Haskell, but lets you build C abstract syntax trees using C's concrete syntax.
That would allow to really embed any kind of language in a more or less easy way into haskell, provided that code can be translated into legal haskell.
Is there anything that prevent these features.
Check out GHC 7. The ability to quasiquote top-level definitions is being used in the Haskell version of PADS [3].
Thank you
Regards
J-C
Geoff [1] http://new-www.haskell.org/ghc/docs/7.0.1/html/users_guide/template-haskell.... [2] http://hackage.haskell.org/package/language-c-quote [3] http://www.padsproj.org/