
I have written a set of function that generates hsSyn data structures,
in particular HsExpr. I want run these functions at compile time, so
it can generate user code. I do this via Template Haskell and an ugly
hack in TH.
TcSplice.lhs expects an ExpQ monad as result for splice expressions.
I hesitate to rewrite my functions to generate a TH.Exp hierarchy
instead of a (HsExpr RdrName) hierarchy. The hack is to extend TH.Exp
with a new constructor InternalE (HsExpr RdrName) and to add a pattern
to hsSyn/Convert.lhs in
ctvl :: TH.Exp -> CvtM (LHsExpr RdrName)
cvt (InternalE expr) = return expr
This effectively percises the whole TH.Exp -> HsExpr conversion by
providing a Exp constructor with a HsExpr payload, and extending the
conversion to just unwrap this payload.
This enables me to hand HsExpr to the compiler via Template Haskell
via this elegant ugly hack:
foobar =
$(return (InternalE