: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.
Trac metadata
Trac field
Value
Version
6.10.1
Type
FeatureRequest
TypeOfFailure
OtherFailure
Priority
normal
Resolution
Unresolved
Component
GHCi
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Child items
0
Show closed items
No child items are currently assigned. Use child items to break down this issue into smaller parts.
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.
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.)
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.
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.
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)
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.
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...
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 hacked^Wadded to it:
*InteractiveUI Control.Monad> :instances MonadMonad GHCiMonad Lexer.PMonad (Either e)Monad m => Monad (InputT m)Monad MaybeMonad m => Monad (GHC.GhcT m)Monad GhcMonad []Monad IOMonad ((->) 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?
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?
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.
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 Monaddata 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 Monadinstance 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! Monadinstance 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 classPrelude> :instances 'Just<interactive>:1:1: parse error on input ‘'’Prelude> :k 'Just'Just :: k -> Maybe kPrelude> :k JustJust :: 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 ‘'’