summaryrefslogtreecommitdiff
path: root/compiler/utils/Pretty.hs
diff options
context:
space:
mode:
authorMichał Sośnicki <sosnicki.michal@gmail.com>2015-11-18 16:02:53 +0100
committerBen Gamari <ben@smart-cactus.org>2015-11-18 17:31:20 +0100
commitc61759d5917996a10b06a286eb5b776e4069e35c (patch)
tree7fc3b9a29cec4f98e28278d23e5000743d0d3956 /compiler/utils/Pretty.hs
parent07eb258dfcbf8a67e4e931397128b7255356d19e (diff)
downloadhaskell-c61759d5917996a10b06a286eb5b776e4069e35c.tar.gz
Fix inconsistent pretty-printing of type families
After the changes, the three functions used to print type families were identical, so they are refactored into one. Original RHSs of data instance declarations are recreated and printed in user error messages. RHSs containing representation TyCons are printed in the Coercion Axioms section in a typechecker dump. Add vbar to the list of SDocs exported by Outputable. Replace all text "|" docs with it. Fixes #10839 Reviewers: goldfire, jstolarek, austin, bgamari Reviewed By: jstolarek Subscribers: jstolarek, thomie Differential Revision: https://phabricator.haskell.org/D1441 GHC Trac Issues: #10839
Diffstat (limited to 'compiler/utils/Pretty.hs')
-rw-r--r--compiler/utils/Pretty.hs8
1 files changed, 7 insertions, 1 deletions
diff --git a/compiler/utils/Pretty.hs b/compiler/utils/Pretty.hs
index 4aae2c8c53..74d69f23d0 100644
--- a/compiler/utils/Pretty.hs
+++ b/compiler/utils/Pretty.hs
@@ -180,7 +180,7 @@ module Pretty (
sep, cat,
fsep, fcat,
nest,
- hang, punctuate,
+ hang, hangNotEmpty, punctuate,
-- * Predicates on documents
isEmpty,
@@ -563,6 +563,12 @@ nest k p = mkNest k (reduceDoc p)
hang :: Doc -> Int -> Doc -> Doc
hang d1 n d2 = sep [d1, nest n d2]
+-- | Apply 'hang' to the arguments if the first 'Doc' is not empty.
+hangNotEmpty :: Doc -> Int -> Doc -> Doc
+hangNotEmpty d1 n d2 = if isEmpty d1
+ then d2
+ else hang d1 n d2
+
-- | @punctuate p [d1, ... dn] = [d1 \<> p, d2 \<> p, ... dn-1 \<> p, dn]@
punctuate :: Doc -> [Doc] -> [Doc]
punctuate _ [] = []