summaryrefslogtreecommitdiff
path: root/libraries/template-haskell/Language/Haskell/TH
diff options
context:
space:
mode:
authorSimon Peyton Jones <simonpj@microsoft.com>2015-02-06 14:48:33 +0000
committerSimon Peyton Jones <simonpj@microsoft.com>2015-02-06 14:48:33 +0000
commit111e5870803bcccd1c0736fdba432f8f9410454f (patch)
tree583acc8e1cab7b76eef6f4fe8ac7a14e18e4cd71 /libraries/template-haskell/Language/Haskell/TH
parentda78af367dfa5050c2c19b758ab046218ee4dd91 (diff)
downloadhaskell-111e5870803bcccd1c0736fdba432f8f9410454f.tar.gz
Put parens around (ty :: kind) when pretty-printing TH syntax
See Note [Pretty-printing kind signatures] in Language.Haskell.TH.Ppr.hs, and Trac #10050.
Diffstat (limited to 'libraries/template-haskell/Language/Haskell/TH')
-rw-r--r--libraries/template-haskell/Language/Haskell/TH/Ppr.hs15
1 files changed, 13 insertions, 2 deletions
diff --git a/libraries/template-haskell/Language/Haskell/TH/Ppr.hs b/libraries/template-haskell/Language/Haskell/TH/Ppr.hs
index 4ba43f3973..e5cab65185 100644
--- a/libraries/template-haskell/Language/Haskell/TH/Ppr.hs
+++ b/libraries/template-haskell/Language/Haskell/TH/Ppr.hs
@@ -498,14 +498,25 @@ pprParendType PromotedNilT = text "'[]"
pprParendType PromotedConsT = text "(':)"
pprParendType StarT = char '*'
pprParendType ConstraintT = text "Constraint"
+pprParendType (SigT ty k) = parens (ppr ty <+> text "::" <+> ppr k)
pprParendType other = parens (ppr other)
instance Ppr Type where
ppr (ForallT tvars ctxt ty)
= text "forall" <+> hsep (map ppr tvars) <+> text "."
<+> sep [pprCxt ctxt, ppr ty]
- ppr (SigT ty k) = ppr ty <+> text "::" <+> ppr k
- ppr ty = pprTyApp (split ty)
+ ppr ty = pprTyApp (split ty)
+ -- Works, in a degnerate way, for SigT, and puts parens round (ty :: kind)
+ -- See Note [Pretty-printing kind signatures]
+
+{- Note [Pretty-printing kind signatures]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+GHC's parser only recognises a kind signature in a type when there are
+parens around it. E.g. the parens are required here:
+ f :: (Int :: *)
+ type instance F Int = (Bool :: *)
+So we always print a SigT with parens (see Trac #10050). -}
+
pprTyApp :: (Type, [Type]) -> Doc
pprTyApp (ArrowT, [arg1,arg2]) = sep [pprFunArgType arg1 <+> text "->", ppr arg2]