[Haskell-cafe] Typed TemplateHaskell?
Tillmann Rendel
rendel at informatik.uni-marburg.de
Wed May 23 19:20:16 CEST 2012
Hi Ilya,
Ilya Portnov wrote:
> As far as can I see, using features of last GHC one could write typed TH
> library relatively easily, and saving backwards compatibility.
>
> For example, now we have Q monad and Exp type in "template-haskell"
> package. Let's imagine some new package, say "typed-template-haskell",
> with new TQ monad and new polymorphic type Exp :: * -> *. Using last
> GHC's features, one will easily write something like "expr :: Exp
> String", which will mean that "expr" represents a string expression. And
> we will need a new function, say runTQ :: TQ a -> Q a (or some more
> complicated type), which will turn TypedTemplateHaskell's constructs
> into plain TH.
That would be a good thing to have. But it might be quite hard to
implement. For example, I guess you might want to have functions like
this one:
apply :: Exp (a -> b) -> Exp a -> Exp b
This function takes two typed expressions and produces an application.
The types ensure that the generated application will typecheck. Cool.
But can you do the same thing for lambdas? Lambdas create functions, so
the type would be something like the following:
lambda :: ... -> Exp (a -> b)
But what would you put instead of the ...?
I fear that overall, you would have to reimplement Haskell's type system
in Haskell's type system. Which sounds like a cool thing to do, but
maybe not so easily.
Tillmann
More information about the Haskell-Cafe
mailing list