[Haskell-cafe] Multiple stages in Template Haskell

Ch. A. Herrmann herrmann at uni-passau.de
Wed Oct 11 04:05:45 EDT 2006


Hi,

because Template Haskell is a compile-time metaprogramming language, 
there is no metaprogram
left after the first stage. Thus, it does not make sense, conceptually, 
to have more than one stage.
In contrast, in MetaOCaml, you can generate code at run time that 
generates code at run time that ...

In Template Haskell, you have the possibility of a sequence of files 
where file n+1 makes use
of the templates defined in file n; and maybe sometime this will be 
simplified such that you can
have all definitions in one file. Anyway, you do not need multiple stages.

Concerning the stage count, perhaps you just forgot to insert a 
quasi-quote at some place, e.g., at:

$ [| zipN ...

--
 Christoph

Lyle Kopnicky wrote:

> Hi folks,
>
> I noticed that in Template Haskell, you can only have one level of 
> splicing or quasi-quoting. E.g., you can't write:
>
>    $(zipN ($(sel 2 3) ("zip level",3,()))) ['a'..'Z'] [1..] (words 
> "now is the time")
>
> Because you can't have a splice inside a splice. But wouldn't it be 
> handy to use all these macros when defining other macros?
>
> This would be like stages in MetaML, which have no such limitation. 
> But all the stages but the last one would be evaluated at compile 
> time. The compiler would look for the deepest level of nested splices 
> and evaluate it first.
>
> On the other hand, I can understand why you wouldn't include splices 
> and quasi-quotes in the Language.Haskell.TH.Syntax - programmers could 
> write functions that dynamically created arbitrarily (even infinitely) 
> nested splices - so it would be undecidable where to start.
>
> I'm wondering if there's some reason this restriction is imposed. Is 
> it particularly difficult to implement, or are there more theoretical 
> problems? Does that mean I'm volunteering? ;)
>
> - Lyle
>
> _______________________________________________
> 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