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

#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 Keywords: TypeFamilies | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- Load this code: {{{#!hs {-# LANGUAGE TypeFamilies #-} module Bug where type family F a where F [Int] = Bool F [a] = Double F (a b) = Char }}} into GHCi 8.0.1, 8.0.2, or HEAD, and run `:i F`. You'll see this: {{{ $ /opt/ghc/8.0.2/bin/ghci Bug.hs GHCi, version 8.0.2: http://www.haskell.org/ghc/ :? for help Loaded GHCi configuration from /home/rgscott/.ghci [1 of 1] Compiling Bug ( Bug.hs, interpreted ) Ok, modules loaded: Bug. λ> :i F type family F a :: * where F [Int] = Bool [a] F [a] = Double [b, (a :: * -> *)] F (a b) = Char -- Defined at Bug.hs:4:1 }}} Compare this with GHCi 7.10.3, where the pretty-printing is far more sane: {{{ $ /opt/ghc/7.10.3/bin/ghci Bug.hs GHCi, version 7.10.3: http://www.haskell.org/ghc/ :? for help [1 of 1] Compiling Bug ( Bug.hs, interpreted ) Ok, modules loaded: Bug. λ> :i F type family F a :: * where F [Int] = Bool F [a] = Double F (a b) = Char -- Defined at Bug.hs:4:1 }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13420 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#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

#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: | -------------------------------------+------------------------------------- Comment (by goldfire): I do remember that this change was intentional (that is, I'm not surprised by your report) but the reasons are cloudy. I'd be happy if the binders were printed only with `-fprint-explicit-foralls` and agree that doing so is an improvement. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13420#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13420: Bizarre pretty-printing of closed type families in GHCi -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: patch Priority: normal | Milestone: 8.4.1 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): Phab:D3497 Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * status: new => patch * differential: => Phab:D3497 * milestone: => 8.4.1 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13420#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13420: Bizarre pretty-printing of closed type families in GHCi
-------------------------------------+-------------------------------------
Reporter: RyanGlScott | Owner: (none)
Type: bug | Status: patch
Priority: normal | Milestone: 8.4.1
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): Phab:D3497
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Ben Gamari

#13420: Bizarre pretty-printing of closed type families in GHCi -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: 8.4.1 Component: GHCi | Version: 8.0.2 Resolution: fixed | Keywords: TypeFamilies Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D3497 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: patch => closed * resolution: => fixed -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13420#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC