Opened 8 years ago

Closed 8 years ago

#5417 closed bug (fixed)

GHCi browse gets type families wrong

Reported by: simonpj Owned by:
Priority: normal Milestone:
Component: Compiler Version: 7.2.1
Keywords: Cc: stegeman@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case: ghci/scripts/T5417
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


Reported by Luite Stegeman

--------- A.hs
module A where
  import B

--------- B.hs
{-# LANGUAGE TypeFamilies #-}
module B where
  import qualified C

  data B1 a = B1 a

  instance C.C1 (B1 a) where
    data C.F (B1 a) = B2 a

  data family D a

---------- C.hs
{-# LANGUAGE TypeFamilies #-}
module C where

  class C1 a where
    data F a :: *

Nnw use ghci 7.2.1:

ghci A
*A> :info F
data family F a 	-- Defined at C.hs:6:8

ghci B
*B> :browse
data B1 a = B1 a
data instance B.R:FB1 (B1 a) = B2 a
data family D a
data family F a
   -- Why is F displayed here?
   -- What is B.R:FB1?

*B> :info F
Top level: Not in scope: data constructor `F'

*B> :info C.F
data family C.F a 	-- Defined at C.hs:6:8

But with ghci 7.0.4:

ghci A
*A> :info F
Top level: Not in scope: data constructor `F'

Change History (7)

comment:2 Changed 8 years ago by luite

I don't think this is limited to :browse, since I noticed this problem when something like this didn't compile anymore with 7.2.1:

--------- D.hs
module D where

data F = F
--------- E.hs
module E where

import D
import B

x :: F
-- ghc 7.0.4
> ghci E
Ok, modules loaded: E, D, B, C.
*E> :type x
x :: F
*E> :info F
data F = F 	-- Defined at D.hs:4:6
-- ghc 7.2.1
> ghci E
[4 of 4] Compiling E                ( E.hs, interpreted )
    Ambiguous occurrence `F'
    It could refer to either `D.F', imported from D at E.hs:4:1-8
                          or `B.F', imported from B at E.hs:5:1-8
Failed, modules loaded: D, C, B.

comment:3 in reply to:  2 Changed 8 years ago by luite

whoops forgot the line

x = undefined

in E.hs

comment:4 Changed 8 years ago by guest

What is the conclusion? Is this a feature, not a bug, and it needs to be fixed in the user code?

comment:5 Changed 8 years ago by simonpj

It's mixture of things.

  • There are definitely bugs related to the display of associated types (hence the strange B.R:FB1.
  • The :browse command makes an odd choice for the scope in which id displays its results, which in turn says what gets displayed qualified and what does not. Currently it displays the results of :browse M in the scope that would arise from import Prelude; import M. This is pretty confusing.

I'm about to commit a patch to

  • Fix the bugs
  • Arrange that :browse always displays its results in the current scope just like :info, :type and so on. Simon and I think that'll be much less confusing.


comment:6 Changed 8 years ago by simonpj

This patch makes :browse consistent

commit cd3d6f884ee7f2e425359e910a0effc5a27c71db
Author: Simon Peyton Jones <>
Date:   Mon Aug 22 07:57:50 2011 +0100

    In :browse, always print output in the *current* context
    Previously :browse M (without !) printed output relative to
    a context that was neither the current one, nor the top-level
    context of M, but rather that established
         import Prelude
         import M
    This was pretty confusing, so Simon and I agreed to use
    a simple, uniform rule: output in GHC is always relative
    to the current context.


 docs/users_guide/ghci.xml |   54 +++++++++++++++++++++++++-------------------
 ghc/InteractiveUI.hs      |   30 +++++++++---------------
 2 files changed, 42 insertions(+), 42 deletions(-)

These two fix the way that :browse displays declarations, esp ones involving associated types

commit 9c889adc05ce9f16b20abb35db417e52e615e249
Author: Simon Peyton Jones <>
Date:   Mon Aug 22 07:59:52 2011 +0100

    Pretty-printing improvements in HsSyn


 compiler/hsSyn/HsBinds.lhs |   30 ++++++++++++++++--------------
 compiler/hsSyn/HsDecls.lhs |   34 +++++++++++++++++++---------------
 2 files changed, 35 insertions(+), 29 deletions(-)

commit d50a0937b4b5b0fd2f3882e15c4ddd7110d4ab45
Author: Simon Peyton Jones <>
Date:   Mon Aug 22 08:03:44 2011 +0100

    Make pprTyThingInContenxt handle associated types right
    Just as we want to display a data constructor as part of its
    parent data type declaration, so with associated types.  This
    was simply missing before.

 compiler/main/GHC.hs        |    2 +-
 compiler/main/HscTypes.lhs  |   23 ++++++++-
 compiler/main/PprTyThing.hs |  113 ++++++++++++++++++++++--------------------
 compiler/types/TyCon.lhs    |   11 +++--
 4 files changed, 88 insertions(+), 61 deletions(-)

And this one fixes some other glitches in the interaction of instance declarations with associated types

commit f76f0d0e5ec81244951994be1d1acee5650b0b75
Author: Simon Peyton Jones <>
Date:   Mon Aug 22 08:08:50 2011 +0100

    A batch of changes related to the handling of binders in instance decls
    The issue is that in
        instnace C T where
          data S = ...
          f = ...
    neither S nor f is really a binder; they are *occurrences*.  Moreover
    Haskell dictates that these particular occurrences are disambiguated
    by looking at the class whose instance they occur in.
    Some of this was not handled right for associated types.  And
    RnNames.getLocalNonValBinders was a bit messhy; this patch tidies it
    (And thenM is finally gone from RnSource.)

 compiler/basicTypes/RdrName.lhs   |   14 +--
 compiler/deSugar/DsMeta.hs        |    2 +-
 compiler/hsSyn/HsTypes.lhs        |   16 ++--
 compiler/rename/RnBinds.lhs       |    2 +-
 compiler/rename/RnEnv.lhs         |   27 +++--
 compiler/rename/RnNames.lhs       |  208 ++++++++++++++++++++-----------------
 compiler/rename/RnSource.lhs      |  205 ++++++++++++++++--------------------
 compiler/typecheck/TcRnDriver.lhs |    7 +-
 8 files changed, 241 insertions(+), 240 deletions(-)

comment:7 Changed 8 years ago by simonpj

Resolution: fixed
Status: newclosed
Test Case: ghci/scripts/T5417

Test added, so I'm closing. Thanks for pointing out the bug(s)!


Note: See TracTickets for help on using tickets.