Infelicities with :instances
In ongoing work to introduce homogeneous equality, I came across the need to edit InteractiveEval.checkForExistence
, part of the implementation of the new :instances
command. The (accepted) proposal lives at https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0166-ghci-instances.rst and the original MR that introduced the feature is at !720 (closed).
In trying to understand checkForExistence
and friends, I had to examine the feature in some detail, and I found several ways it could be improved. I'm making one master ticket here, in the hopes that @xldenis (the original proposer and implementor) might revisit this all in one go. If need be, we can split this up into multiple tickets.
-
The user's guide for the :instances
command is not alphabetized w.r.t. other commands in that chapter of the manual. This really did stop me from being able to find the entry! -
If I say :instances Either _ Int
, I need-XPartialTypeSignatures
enabled. This is not described in the proposal, and I don't think it's a good design. Language extensions are gateways to more powerful features, but if a user types:instances
at the command line, they should get what they want. Along similar lines, even with-XPartialTypeSignatures
,:instances Either _ Int
produces warnings about typed holes. These are not helpful in this context. -
At first, I tried e.g. :instances Show [_]
, hoping to seeinstance Show a => Show [a]
. But I got nothing. That's because:instances
expects a type, not a constraint. Sensible enough, I suppose. But it would be very nice if I got some help in figuring this out. To wit: if the type given to:instances
has kindConstraint
and no instances are found (it is possible to have classes whose argument has kindConstraint
), GHC should print a message advising the user to write the type, not the constraint. -
With appropriate flags, if I say :instances [_]
, I get a listing of instances all with_
in them. I actually think it would be more ergonomic just to keep the original tyvars (usually,a
) instead of adding underscores. If I use two underscores (:instances Either _ _
), one is renamed to_1
(which is actually helpful), but it's even uglier. -
I'm actually still trying to figure out what checkForExistence
really does. In particular, I'm worried about equality instance constraints, because it looks likecheckForExistence
will mishandle them. (They might be unlifted, and the function implicitly treats them as lifted. This is an easy mistake to make, but happens to hamper what I'm in the middle of.) So I triedclass C a; instance a ~ b => C (Either a b)
. If I ask for:instances Either _ Int
, I don't see theC
instance. (I do get it for:instances Either Int Int
.) So I'm not sure what to expect here. I think myC
instance should be reported here.
I think I know how to proceed now, and none of these is really ruining my day, but it seems a little improvement here would be nice. Thanks!