[commit: ghc] master: Better pretty-printing of forall types (37ef703)

git at git.haskell.org git at git.haskell.org
Thu Oct 4 15:03:46 UTC 2018


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/37ef7031b95c97e7c8bc1d14bc95554a3bac2873/ghc

>---------------------------------------------------------------

commit 37ef7031b95c97e7c8bc1d14bc95554a3bac2873
Author: Simon Peyton Jones <simonpj at microsoft.com>
Date:   Wed Oct 3 15:58:13 2018 +0100

    Better pretty-printing of forall types
    
    Currently forall-types with a lot of type variables,
    or type variables with big kinds, are pretty-printed too
    horizontally, and dribble off to the right in an illegible
    way.
    
    This patch treats the type variables as a group, and uses
    'fsep' to lay them out decently.


>---------------------------------------------------------------

37ef7031b95c97e7c8bc1d14bc95554a3bac2873
 compiler/iface/IfaceType.hs                | 13 +++++++------
 testsuite/tests/ghci/scripts/T12550.stdout |  4 ++--
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/compiler/iface/IfaceType.hs b/compiler/iface/IfaceType.hs
index 23b09da..264dfa0 100644
--- a/compiler/iface/IfaceType.hs
+++ b/compiler/iface/IfaceType.hs
@@ -929,9 +929,10 @@ ppr_iface_forall_part show_forall tvs ctxt sdoc
 pprIfaceForAll :: [IfaceForAllBndr] -> SDoc
 pprIfaceForAll [] = empty
 pprIfaceForAll bndrs@(Bndr _ vis : _)
-  = add_separator (forAllLit <+> doc) <+> pprIfaceForAll bndrs'
+  = sep [ add_separator (forAllLit <+> fsep docs)
+        , pprIfaceForAll bndrs' ]
   where
-    (bndrs', doc) = ppr_itv_bndrs bndrs vis
+    (bndrs', docs) = ppr_itv_bndrs bndrs vis
 
     add_separator stuff = case vis of
                             Required -> stuff <+> arrow
@@ -943,12 +944,12 @@ pprIfaceForAll bndrs@(Bndr _ vis : _)
 -- No anonymous binders here!
 ppr_itv_bndrs :: [IfaceForAllBndr]
              -> ArgFlag  -- ^ visibility of the first binder in the list
-             -> ([IfaceForAllBndr], SDoc)
+             -> ([IfaceForAllBndr], [SDoc])
 ppr_itv_bndrs all_bndrs@(bndr@(Bndr _ vis) : bndrs) vis1
   | vis `sameVis` vis1 = let (bndrs', doc) = ppr_itv_bndrs bndrs vis1 in
-                         (bndrs', pprIfaceForAllBndr bndr <+> doc)
-  | otherwise   = (all_bndrs, empty)
-ppr_itv_bndrs [] _ = ([], empty)
+                         (bndrs', pprIfaceForAllBndr bndr : doc)
+  | otherwise   = (all_bndrs, [])
+ppr_itv_bndrs [] _ = ([], [])
 
 pprIfaceForAllCo :: [(IfLclName, IfaceCoercion)] -> SDoc
 pprIfaceForAllCo []  = empty
diff --git a/testsuite/tests/ghci/scripts/T12550.stdout b/testsuite/tests/ghci/scripts/T12550.stdout
index 0955db3..c7173fc 100644
--- a/testsuite/tests/ghci/scripts/T12550.stdout
+++ b/testsuite/tests/ghci/scripts/T12550.stdout
@@ -57,8 +57,8 @@ datatypeName
     Datatype d ⇒
     t d f a → [Char]
 class Datatype (d ∷ k) where
-  datatypeName ∷ ∀ k1 (t ∷ k → (k1 → ★) → k1 → ★) (f ∷ k1
-                                                       → ★) (a ∷ k1).
+  datatypeName ∷ ∀ k1 (t ∷ k → (k1 → ★) → k1 → ★) (f ∷ k1 → ★)
+                   (a ∷ k1).
                  t d f a → [Char]
   ...
   	-- Defined in ‘GHC.Generics’



More information about the ghc-commits mailing list