summaryrefslogtreecommitdiff
path: root/libraries/template-haskell/Language/Haskell/TH/Ppr.hs
diff options
context:
space:
mode:
authorOleg Grenrus <oleg.grenrus@iki.fi>2023-03-27 20:55:15 +0300
committerMarge Bot <ben+marge-bot@smart-cactus.org>2023-04-12 12:32:57 -0400
commitebd8918b7c50ae51921664e24fac0de4376ffcf9 (patch)
tree39f7112ed74735163f2208abe7e491bdbdaad757 /libraries/template-haskell/Language/Haskell/TH/Ppr.hs
parentecf22da3c6d992d76fbb8e970b4ffbabb445d38a (diff)
downloadhaskell-ebd8918b7c50ae51921664e24fac0de4376ffcf9.tar.gz
Allow generation of TTH syntax with TH
In other words allow generation of typed splices and brackets with Untyped Template Haskell. That is useful in cases where a library is build with TTH in mind, but we still want to generate some auxiliary declarations, where TTH cannot help us, but untyped TH can. Such example is e.g. `staged-sop` which works with TTH, but we would like to derive `Generic` declarations with TH. An alternative approach is to use `unsafeCodeCoerce`, but then the derived `Generic` instances would be type-checked only at use sites, i.e. much later. Also `-ddump-splices` output is quite ugly: user-written instances would use TTH brackets, not `unsafeCodeCoerce`. This commit doesn't allow generating of untyped template splices and brackets with untyped TH, as I don't know why one would want to do that (instead of merging the splices, e.g.)
Diffstat (limited to 'libraries/template-haskell/Language/Haskell/TH/Ppr.hs')
-rw-r--r--libraries/template-haskell/Language/Haskell/TH/Ppr.hs2
1 files changed, 2 insertions, 0 deletions
diff --git a/libraries/template-haskell/Language/Haskell/TH/Ppr.hs b/libraries/template-haskell/Language/Haskell/TH/Ppr.hs
index 034d2687b3..dbe3cb85df 100644
--- a/libraries/template-haskell/Language/Haskell/TH/Ppr.hs
+++ b/libraries/template-haskell/Language/Haskell/TH/Ppr.hs
@@ -232,6 +232,8 @@ pprExp _ (LabelE s) = text "#" <> text s
pprExp _ (ImplicitParamVarE n) = text ('?' : n)
pprExp _ (GetFieldE e f) = pprExp appPrec e <> text ('.': f)
pprExp _ (ProjectionE xs) = parens $ hcat $ map ((char '.'<>) . text) $ toList xs
+pprExp _ (TypedBracketE e) = text "[||" <> ppr e <> text "||]"
+pprExp _ (TypedSpliceE e) = text "$$" <> pprExp appPrec e
pprFields :: [(Name,Exp)] -> Doc
pprFields = sep . punctuate comma . map (\(s,e) -> pprName' Applied s <+> equals <+> ppr e)