Provides an instance that translates haskell-src-exts expression trees into Template Haskell expression trees in a way that depends only on the haskell-src-exts syntax tree and agreement on the pretty-printed representation of Haskell between haskell-src-exts pretty-printer and Template Haskell quotations (as opposed to depending on both TH and haskell-src-exts syntax tree representations).
Instead of converting between data types, haskell-src-exts syntax trees are pretty-printed and wrapped in a TH quotation which is then interpreted as a Haskell program, yielding a TH Exp tree. Free variables in the haskell-src-exts tree are preserved by lifting them to TH splices prior to pretty-printing.
parseToTH "let x = 1 in x + y" =
Right (LetE [ValD (VarP x_1) (NormalB (LitE (IntegerL 1))) ]
(InfixE (Just (VarE x_1)) (VarE GHC.Num.+) (Just (VarE y))))
Translate a Language.Haskell.Exts.Exp (haskell-src-exts) syntax tree to a Language.Haskell.TH.Exp (template-haskell) syntax tree
Parse a string to a Language.Haskell.TH.Exp (template-haskell) expression via intermediate representation as a Exts.Exp tree.
Parse a string to a tree of type
t, via intermediate representation
as a tree of type
s. Requires a witness of the intermediate type
to be passed as the first argument.
If parsing fails then
parseToTarget s = Left s, otherwise
parseToTarget s = Right t where
t is the parsed tree.