summaryrefslogtreecommitdiff
path: root/libraries/template-haskell
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/template-haskell')
-rw-r--r--libraries/template-haskell/Language/Haskell/TH/Ppr.hs21
-rw-r--r--libraries/template-haskell/Language/Haskell/TH/Syntax.hs11
-rw-r--r--libraries/template-haskell/changelog.md6
3 files changed, 28 insertions, 10 deletions
diff --git a/libraries/template-haskell/Language/Haskell/TH/Ppr.hs b/libraries/template-haskell/Language/Haskell/TH/Ppr.hs
index 899d27c38f..3f79920a0b 100644
--- a/libraries/template-haskell/Language/Haskell/TH/Ppr.hs
+++ b/libraries/template-haskell/Language/Haskell/TH/Ppr.hs
@@ -66,7 +66,7 @@ instance Ppr Info where
case mb_d of { Nothing -> empty; Just d -> ppr d }]
ppr_sig :: Name -> Type -> Doc
-ppr_sig v ty = ppr v <+> dcolon <+> ppr ty
+ppr_sig v ty = pprName' Applied v <+> dcolon <+> ppr ty
pprFixity :: Name -> Fixity -> Doc
pprFixity _ f | f == defaultFixity = empty
@@ -507,20 +507,24 @@ instance Ppr Con where
<+> pprBangType st2
ppr (ForallC ns ctxt (GadtC c sts ty))
- = commaSep c <+> dcolon <+> pprForall ns ctxt <+> pprGadtRHS sts ty
+ = commaSepApplied c <+> dcolon <+> pprForall ns ctxt
+ <+> pprGadtRHS sts ty
ppr (ForallC ns ctxt (RecGadtC c vsts ty))
- = commaSep c <+> dcolon <+> pprForall ns ctxt
+ = commaSepApplied c <+> dcolon <+> pprForall ns ctxt
<+> pprRecFields vsts ty
ppr (ForallC ns ctxt con)
= pprForall ns ctxt <+> ppr con
ppr (GadtC c sts ty)
- = commaSep c <+> dcolon <+> pprGadtRHS sts ty
+ = commaSepApplied c <+> dcolon <+> pprGadtRHS sts ty
ppr (RecGadtC c vsts ty)
- = commaSep c <+> dcolon <+> pprRecFields vsts ty
+ = commaSepApplied c <+> dcolon <+> pprRecFields vsts ty
+
+commaSepApplied :: [Name] -> Doc
+commaSepApplied = commaSepWith (pprName' Applied)
pprForall :: [TyVarBndr] -> Cxt -> Doc
pprForall ns ctxt
@@ -731,7 +735,12 @@ instance Ppr Loc where
-- Takes a list of printable things and prints them separated by commas followed
-- by space.
commaSep :: Ppr a => [a] -> Doc
-commaSep = sep . punctuate comma . map ppr
+commaSep = commaSepWith ppr
+
+-- Takes a list of things and prints them with the given pretty-printing
+-- function, separated by commas followed by space.
+commaSepWith :: (a -> Doc) -> [a] -> Doc
+commaSepWith pprFun = sep . punctuate comma . map pprFun
-- Takes a list of printable things and prints them separated by semicolons
-- followed by space.
diff --git a/libraries/template-haskell/Language/Haskell/TH/Syntax.hs b/libraries/template-haskell/Language/Haskell/TH/Syntax.hs
index f571d6b16f..a3284c53eb 100644
--- a/libraries/template-haskell/Language/Haskell/TH/Syntax.hs
+++ b/libraries/template-haskell/Language/Haskell/TH/Syntax.hs
@@ -67,7 +67,7 @@ class Monad m => Quasi m where
qLookupName :: Bool -> String -> m (Maybe Name)
-- True <=> type namespace, False <=> value namespace
qReify :: Name -> m Info
- qReifyFixity :: Name -> m Fixity
+ qReifyFixity :: Name -> m (Maybe Fixity)
qReifyInstances :: Name -> [Type] -> m [Dec]
-- Is (n tys) an instance?
-- Returns list of matching instance Decs
@@ -355,10 +355,13 @@ and to get information about @D@-the-type, use 'lookupTypeName'.
reify :: Name -> Q Info
reify v = Q (qReify v)
-{- | @reifyFixity nm@ returns the fixity of @nm@. If a fixity value cannot be
-found, 'defaultFixity' is returned.
+{- | @reifyFixity nm@ attempts to find a fixity declaration for @nm@. For
+example, if the function @foo@ has the fixity declaration @infixr 7 foo@, then
+@reifyFixity 'foo@ would return @'Just' ('Fixity' 7 'InfixR')@. If the function
+@bar@ does not have a fixity declaration, then @reifyFixity 'bar@ returns
+'Nothing', so you may assume @bar@ has 'defaultFixity'.
-}
-reifyFixity :: Name -> Q Fixity
+reifyFixity :: Name -> Q (Maybe Fixity)
reifyFixity nm = Q (qReifyFixity nm)
{- | @reifyInstances nm tys@ returns a list of visible instances of @nm tys@. That is,
diff --git a/libraries/template-haskell/changelog.md b/libraries/template-haskell/changelog.md
index 9564e95678..1c0919a8a2 100644
--- a/libraries/template-haskell/changelog.md
+++ b/libraries/template-haskell/changelog.md
@@ -37,6 +37,12 @@
* Add `reifyConStrictness` to query a data constructor's `DecidedStrictness`
values for its fields (#10697)
+ * The `ClassOpI`, `DataConI`, and `VarI` constructors no longer have a
+ `Fixity` field. Instead, all `Fixity` information for a given `Name` is
+ now determined through the `reifyFixity` function, which returns `Just` the
+ fixity if there is an explicit fixity declaration for that `Name`, and
+ `Nothing` otherwise (#10704 and #11345)
+
* TODO: document API changes and important bugfixes