Opened 9 years ago

Last modified 21 months ago

#2986 new feature request

:info printing instances often isn't wanted

Reported by: Remi Owned by: Remi
Priority: lowest Milestone:
Component: GHCi Version: 6.10.1
Keywords: :info instances Cc: glasgow-haskell-users@…, hvr
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: #1581 Differential Rev(s):
Wiki Page:

Description

:info shows all instances of types/classes, which often obscures the info I'm actually interested in. See the output of e.g. ":info Show" or ":info [] Maybe Int": The class and types are rather lost in between the instances. My proposal is to add an option to suppress the printing of instances. With the attached patch for 6.10.1 (although it applies to HEAD too), ":info -Show" will only print the class.

Attachments (2)

ghci-info-no-instances.patch (2.5 KB) - added by Remi 9 years ago.
patch to optionally not print instances with :info
0001-Split-ghci-info-into-info-and-instances.patch (4.9 KB) - added by Remi 3 years ago.

Download all attachments as: .zip

Change History (35)

Changed 9 years ago by Remi

patch to optionally not print instances with :info

comment:1 Changed 9 years ago by simonpj

Cc: glasgow-haskell-users@… added
difficulty: Unknown

The goal of being able to ask (in GHCi) about a class without seeing all its instances seems to be a good one. But what about syntax? Is Remi's proposed UI the right one? He suggests:

   :info Show     -- See class definition and instances
   :info -Show    -- See class definition only

But an alternative could be:

   :info Show        -- See class definition only
   :instances Show   -- See instances of Show
   :instances Bool   -- See instances of Bool

That'd give upward room to grow. For example, one might want

   :instances Show (Tree _)   -- See instances of form (Show (Tree ...))

Maybe there are other alternatives.

So for me the user interface is the issue. If we can evolve a consensus I'm sure it won't be hard to implement. Would anyone like to volunteer to drive the debate?

With that in mind I'm trying the experiment of adding ghc-users to the cc-list. Debate on the list, record proposals, and pros/cons on this ticket.

Simon

comment:2 Changed 9 years ago by Remi

I don't particularly care for what UI is used exactly, adding a flag to :info seemed simply the easiest way to solve the issue for me. So splitting the thing into :info and :instances is perfectly fine with me, except that they share a common prefix, and I rather like being able to just type

:i Show

The other thing is that I can imagine more complicated ways of searching for instances would perhaps better be done by e.g. hoogle. (hoogle+ghci-integration or something.)

comment:3 Changed 9 years ago by simonpj

I don't particularly care either! But as your follow-up comment points out, it's easy to design a UI and forget something -- in this case I'd forgotten the useful :i abbreviation. So there is real design work to do. It's easier to point out a missing feature than to design the feature to fill the hole.

So what I'm suggesting is that someone (you, if you like) incites a debate and helps it towards a consensus. That doesn't need GHC HQ. Then we (or indeed someone else) can implement it.

Simon

comment:4 Changed 9 years ago by igloo

Milestone: 6.10 branch

There is actually no requirement that command abbreviations are unique, i.e. we could make :i mean :info even if we also had a :instances command.

For example, :b means :break even though we also have :back, :browse and :browse!.

comment:5 Changed 9 years ago by simonpj

Capturing a bit more email; Simon M writes: My vote would be:

:info class Show
:info type Show
:info instance Show

where :info Show displays information about everything called "Show".

I know that classes and types share the same namespace currently, but it might not always be so.

comment:6 Changed 9 years ago by igloo

Milestone: 6.10 branch6.12 branch

comment:7 Changed 7 years ago by igloo

Milestone: 6.12 branch6.12.3

comment:8 Changed 7 years ago by igloo

Milestone: 6.12.36.14.1
Priority: normallow

comment:9 Changed 7 years ago by igloo

Milestone: 7.0.17.0.2

comment:10 Changed 7 years ago by igloo

Milestone: 7.0.27.2.1

comment:11 Changed 6 years ago by igloo

Milestone: 7.2.17.4.1

comment:12 Changed 6 years ago by igloo

Milestone: 7.4.17.6.1
Priority: lowlowest

comment:13 Changed 6 years ago by YitzGale

Type of failure: None/Unknown

This suggestion enjoyed universal support, and a patch was provided. It was also universally agreed that the exact syntax isn't that important. It ended up being neglected only due to bikeshedding over the admittedly minor syntax issue.

I propose that instead of the automated priority demotion that this issue has now suffered, the provided patch should be applied forthwith. Unless someone who prefers a different syntax cares enough to provide an alternative patch immediately, in which case that one should be applied forthwith instead.

comment:14 in reply to:  13 Changed 6 years ago by spl

Replying to YitzGale:

I propose that instead of the automated priority demotion that this issue has now suffered, the provided patch should be applied forthwith.

I agree with this, and I would like to see this in GHCi.

One small thing... Is it possible to add a brief description of '-' in the command's help? To be consistent with other commands (as well as mnemonically useful), perhaps (-: minus instances)

comment:15 Changed 6 years ago by Remi

Perhaps unsurprising, I second the suggestion to apply this patch.

comment:16 Changed 6 years ago by simonpj

UI suggestion. I suggest that

  • :info C never mentions instances of C
  • :instance C describes all instances involving C

There's also a current bug which is that we don't currently report type-family instance at all.

I personally dislike the "-" syntax; very un-discoverable.

Simon

comment:17 Changed 6 years ago by spl

I like that even better, Simon, though I would use :instances and keep :i as the shortcut for :info as was mentioned in previous comments. It appears that you care the most about the UI here and nobody is really in disagreement, so I think you should use whatever you find appropriate.

comment:18 Changed 6 years ago by Remi

The reason I chose the minus-version is because it was the smallest version, and didn't change the default behaviour, but I personally prefer Simon's suggestion too, at least if :i keeps meaning :info...

comment:19 Changed 6 years ago by simonpj

OK good. Would you care to modify your patch to do that? I think it's fine for :i to still mean :info.

It would be great if you could make :instances deal with family instances too.

Thanks

Simon

comment:20 Changed 6 years ago by Remi

Owner: set to Remi

I'm rather busy at my job currently so it may take awhile, but I'll see what I can do :)

comment:21 Changed 5 years ago by igloo

Milestone: 7.6.17.6.2

comment:22 Changed 5 years ago by Remi

This is probably going to be the longest standing feature request ever, but half a year after losing the previous version of my patch I got around to creating a new one. However, before I polish and post it, I'd like to get you guys' opinion on something I hackedWadded to it:

*InteractiveUI Control.Monad> :instances Monad
Monad GHCi
Monad Lexer.P
Monad (Either e)
Monad m => Monad (InputT m)
Monad Maybe
Monad m => Monad (GHC.GhcT m)
Monad Ghc
Monad []
Monad IO
Monad ((->) r)
*InteractiveUI Control.Monad> 
*InteractiveUI Control.Monad> :i Monad []
class Monad m where
  (>>=) :: m a -> (a -> m b) -> m b
  (>>) :: m a -> m b -> m b
  return :: a -> m a
  fail :: String -> m a
  	-- Defined in `GHC.Base'
{- (->) r, [], Either e, Ghc, GHCi, GhcT m, InputT m, IO, Maybe, 
   P -}
data [] a = [] | a : [a] 	-- Defined in `GHC.Types'
{- Alternative, Applicative, Eq, Functor, Monad, MonadPlus, Ord, 
   Outputable, PrintfArg, PrintfType, Read, Show -}

The question being, what do you think about the instance-summary with :info?

comment:23 Changed 5 years ago by igloo

Once we have :instances, I think :info is better without even the summary.

comment:24 Changed 5 years ago by simonpj

Yes, I didn't find the instances summary perspicuous either; I suggest

  • For :info Maybe: (a type constructor)
    data Maybe a = Nothing | Just a	-- Defined in `GHC.Types'
    -- Use :instances to see the 24 instances of `Maybe'
    
  • For :info Monad: (a class)
    class Monad m where
      (>>=) :: m a -> (a -> m b) -> m b
      (>>) :: m a -> m b -> m b
      return :: a -> m a
      fail :: String -> m a
      	-- Defined in `GHC.Base'
    -- Use :instances to see the 8 instances of `Monad'
    

For the :instances can you show the module where the instance comes from?

Simon

comment:25 Changed 3 years ago by thoughtpolice

Milestone: 7.6.27.10.1

Moving to 7.10.1.

comment:26 in reply to:  22 Changed 3 years ago by thomie

Cc: hvr added

Replying to Remi:

This is probably going to be the longest standing feature request ever, but half a year after losing the previous version of my patch I got around to creating a new one.

Remi: do you have a link to your patch? Maybe someone else can finish it.

comment:27 Changed 3 years ago by Remi

Thanks for reminding that I want this feature, hvr :) I had an unexpected day off work and decided to finally dig up and work a bit on that patch:

Prelude> :info Maybe Monad
data Maybe a = Nothing | Just a 	-- Defined in ‘GHC.Base’
Use `:instances Maybe' to see its 10 instance(s)
class Applicative m => Monad (m :: * -> *) where
  (>>=) :: m a -> (a -> m b) -> m b
  (>>) :: m a -> m b -> m b
  return :: a -> m a
  fail :: String -> m a
  	-- Defined in ‘GHC.Base’
Use `:instances Monad' to see its 5 instance(s)

And for instances:

Prelude> :instances Maybe Monad
instance Eq a => Eq (Maybe a) -- Defined in ‘GHC.Base’
instance Monad Maybe -- Defined in ‘GHC.Base’
instance Functor Maybe -- Defined in ‘GHC.Base’
instance Ord a => Ord (Maybe a) -- Defined in ‘GHC.Base’
instance Read a => Read (Maybe a) -- Defined in ‘GHC.Read’
instance Show a => Show (Maybe a) -- Defined in ‘GHC.Show’
instance Applicative Maybe -- Defined in ‘GHC.Base’
instance Foldable Maybe -- Defined in ‘Data.Foldable’
instance Traversable Maybe -- Defined in ‘Data.Traversable’
instance Monoid a => Monoid (Maybe a) -- Defined in ‘GHC.Base’
instance Monad (Either e) -- Defined in ‘Data.Either’
instance Monad [] -- Defined in ‘GHC.Base’
instance Monad Maybe -- Defined in ‘GHC.Base’
instance Monad IO -- Defined in ‘GHC.Base’
instance Monad ((->) r) -- Defined in ‘GHC.Base’
Prelude> :instances! Monad
instance Monad Data.Functor.Identity.Identity
  -- Defined in ‘Data.Functor.Identity’
instance Monad Data.Monoid.Last -- Defined in ‘Data.Monoid’
instance Monad Data.Monoid.First -- Defined in ‘Data.Monoid’
instance Monad f => Monad (Data.Monoid.Alt f)
  -- Defined in ‘Data.Monoid’
instance Monad Text.ParserCombinators.ReadPrec.ReadPrec
  -- Defined in ‘Text.ParserCombinators.ReadPrec’
instance Monad (GHC.ST.ST s) -- Defined in ‘GHC.ST’
instance Control.Arrow.ArrowApply a =>
         Monad (Control.Arrow.ArrowMonad a)
  -- Defined in ‘Control.Arrow’
instance Monad m => Monad (Control.Applicative.WrappedMonad m)
  -- Defined in ‘Control.Applicative’
instance Monad Data.Proxy.Proxy -- Defined in ‘Data.Proxy’
instance Monad Text.ParserCombinators.ReadP.ReadP
  -- Defined in ‘Text.ParserCombinators.ReadP’
instance Monad Text.ParserCombinators.ReadP.P
  -- Defined in ‘Text.ParserCombinators.ReadP’
instance Monad (Either e) -- Defined in ‘Data.Either’
instance Monad [] -- Defined in ‘GHC.Base’
instance Monad Maybe -- Defined in ‘GHC.Base’
instance Monad IO -- Defined in ‘GHC.Base’
instance Monad ((->) r) -- Defined in ‘GHC.Base’
instance Data.Typeable.Internal.Typeable Monad
  -- Defined in ‘Data.Typeable.Internal’

What it doesn't support is at least:

Prelude> :set -XDataKinds 

Prelude> :instances Just
`Just' is not a type or class

Prelude> :instances 'Just
<interactive>:1:1: parse error on input ‘'’

Prelude> :k 'Just
'Just :: k -> Maybe k

Prelude> :k Just
Just :: k -> Maybe k

However, :info doesn't support it either, so I don't think that's that much of an issue right now:

Prelude> :info 'Just
<interactive>:1:1: parse error on input ‘'’

comment:28 Changed 3 years ago by simonpj

Maybe put up a patch on Phab for review, if you think you are done? Don't forget tests, user manual... Thanks!

comment:29 Changed 3 years ago by thoughtpolice

Milestone: 7.10.17.12.1

Moving to 7.12.1 milestone; if you feel this is an error and should be addressed sooner, please move it back to the 7.10.1 milestone.

comment:30 Changed 3 years ago by thoughtpolice

Moving to 7.12.1 milestone; if you feel this is an error and should be addressed sooner, please move it back to the 7.10.1 milestone.

comment:31 Changed 3 years ago by thomie

comment:32 Changed 2 years ago by thoughtpolice

Milestone: 7.12.18.0.1

Milestone renamed

comment:33 Changed 21 months ago by thomie

Milestone: 8.0.1
Note: See TracTickets for help on using tickets.