[GHC] #13420: Bizarre pretty-printing of closed type families in GHCi

GHC ghc-devs at haskell.org
Tue Mar 14 16:40:49 UTC 2017


#13420: Bizarre pretty-printing of closed type families in GHCi
-------------------------------------+-------------------------------------
        Reporter:  RyanGlScott       |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  GHCi              |              Version:  8.0.2
      Resolution:                    |             Keywords:  TypeFamilies
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------
Changes (by RyanGlScott):

 * cc: goldfire (added)


Comment:

 It looks like 6746549772c5cc0ac66c0fce562f297f4d4b80a2 (Kind equalities)
 is the culprit.

 In particular, before that commit, you had to enable `-fprint-explicit-
 foralls` in order to see something like this. In GHCi 7.10.3:

 {{{
 GHCi, version 7.10.3: http://www.haskell.org/ghc/  :? for help
 [1 of 1] Compiling Bug              ( ../Bug.hs, interpreted )
 Ok, modules loaded: Bug.
 λ> :set -fprint-explicit-foralls
 λ> :i F
 type family F a :: * where
     F [Int] = Bool
   forall a. F [a] = Double
   forall (a :: * -> *) b. F (a b) = Char
         -- Defined at ../Bug.hs:4:1
 }}}

 But in GHC 8.0.1 and later, `-fprint-explicit-foralls` has no effect on
 the output. This part of the commit is responsible:

 {{{#!diff
 diff --git a/compiler/iface/IfaceSyn.hs b/compiler/iface/IfaceSyn.hs
 index 307a448..247566c 100644 (file)
 --- a/compiler/iface/IfaceSyn.hs
 +++ b/compiler/iface/IfaceSyn.hs
 @@ -511,14 +511,20 @@ pprAxBranch :: SDoc -> IfaceAxBranch -> SDoc
  -- be a branch for an imported TyCon, so it would be an ExtName
  -- So it's easier to take an SDoc here
  pprAxBranch pp_tc (IfaceAxBranch { ifaxbTyVars = tvs
 -                                  , ifaxbLHS = pat_tys
 -                                  , ifaxbRHS = rhs
 -                                  , ifaxbIncomps = incomps })
 -  = hang (pprUserIfaceForAll tvs)
 -       2 (hang pp_lhs 2 (equals <+> ppr rhs))
 +                                 , ifaxbCoVars = cvs
 +                                 , ifaxbLHS = pat_tys
 +                                 , ifaxbRHS = rhs
 +                                 , ifaxbIncomps = incomps })
 +  = hang ppr_binders 2 (hang pp_lhs 2 (equals <+> ppr rhs))
      $+$
      nest 2 maybe_incomps
    where
 +    ppr_binders
 +      | null tvs && null cvs = empty
 +      | null cvs             = brackets (pprWithCommas pprIfaceTvBndr
 tvs)
 +      | otherwise
 +      = brackets (pprWithCommas pprIfaceTvBndr tvs <> semi <+>
 +                  pprWithCommas pprIfaceIdBndr cvs)
      pp_lhs = hang pp_tc 2 (pprParendIfaceTcArgs pat_tys)
      maybe_incomps = ppUnless (null incomps) $ parens $
                      ptext (sLit "incompatible indices:") <+> ppr incomps
 }}}

 Notice that we're not using `pprUserIfaceForAll` anymore (which consults
 `-fprint-explicit-foralls`), but instead we're using `pprWithCommas`,
 which causes the strange list-like output that we see today.

 Richard, do you have a strong opinion on how closed type families should
 be rendered? My inclination would be to revert back to the old behavior,
 but maybe you had a reason for choosing this strategy.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13420#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list