[Haskell-cafe] Typed TH

adam vogt vogt.adam at gmail.com
Thu Dec 18 18:40:49 UTC 2014


On Thu, Dec 18, 2014 at 12:43 PM, Tom Ellis
<tom-lists-haskell-cafe-2013 at jaguarpaw.co.uk> wrote:
> This is a great idea and looks very useful, which raises the following
> question: Why hasn't this already been done?  Is there some fundamental
> obstruction?  Perhaps someone who has tried this has some wisdom to share.

Sometimes I found myself using:

 foldl appE :: ExpQ -> [ExpQ] -> ExpQ

If you try that with appE_, you end up with a type error "Occurs
check: cannot construct the infinite type: t1 ~ t -> t1". It would
type check if it was a foldl over a hlist, but I don't think that
would be a preferred solution. Since appE_ doesn't work when you don't
know how many times it will be used, I think people would just inline
one possible definition:

 appE_ :: Q (TExp (a -> b)) -> Q (TExp a) -> Q (TExp b)
 appE_ f x = [|| $$f $$x ||]

Secondly, it looks like you can only make a value of type "L String"
by using stringL_, and only consume them with litE_, so I think that
intermediate type does not really help. In other words, I think it is
better to just use the following:

 liftString_ :: String -> Q (TExp String)
 liftString_ = litE_ . stringL_

or just inline the following more general function:

 lift_ :: Lift t => t -> Q (TExp t)
 lift_ x = [|| x ||]

I don't see those extra functions providing something that the typed
bracket / quotation syntax doesn't already provide in a prettier way.


Regards,
Adam


More information about the Haskell-Cafe mailing list