Opened 7 years ago

Last modified 6 years ago

#7261 new feature request

ghci's :info and :browse break encapsulation

Reported by: Feuerbach Owned by:
Priority: normal Milestone:
Component: GHCi Version: 7.6.1
Keywords: Cc: roma@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Other Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

In ghci, :info shows representations of abstract data types. I consider this undesirable, since it breaks abstraction and confuses users.

Example:

Prelude> :m +Data.Unique 
Prelude Data.Unique> :i Unique 
newtype Unique = Data.Unique.Unique Integer
  	-- Defined in `Data.Unique'

I would expect it to behave in the same way as Haddock does, i.e. just show "data Unique".

Same about the :browse command.

Change History (6)

comment:1 Changed 7 years ago by Feuerbach

Cc: roma@… added

comment:2 Changed 6 years ago by igloo

difficulty: Unknown
Milestone: _|_
Type: bugfeature request

Hmm, so I guess you'd get:

Prelude> :i IO
data IO a
        -- Defined in ‛GHC.Types’
Prelude> :i GHC.IO.IO
newtype IO a
  = GHC.Types.IO (GHC.Prim.State# GHC.Prim.RealWorld
                  -> (# GHC.Prim.State# GHC.Prim.RealWorld, a #))
        -- Defined in ‛GHC.Types’

and presumably you would still get:

$ ghci Unique.hs
*Data.Unique> :i Unique
newtype Unique = Unique Integer         -- Defined at Unique.hs:42:9

I'm rather ambivalent about this.

comment:3 Changed 6 years ago by Feuerbach

Oh. Apparently scoping rules in ghci are more complicated than I imagined (re GHC.IO.IO). Where can I read more about them?

comment:4 Changed 6 years ago by igloo

Note that GHC.IO exports the internals of the IO type:

module GHC.IO (
    IO(..), ...
...

Scope rules are defined in http://www.haskell.org/onlinereport/haskell2010/ (probably the Modules chapter in particular).

comment:5 Changed 6 years ago by Feuerbach

Sorry, I wasn't clear. I am puzzled by the fact that in a bare ghci session, without importing any additional modules except Prelude,

1) The type IO is available under the name GHC.IO.IO 2) The data constructor GHC.IO.IO is in scope

In ordinary Haskell, you'd need to import GHC.IO for that to be the case. Hence my question.

Note: See TracTickets for help on using tickets.