Opened 2 years ago

Closed 2 years ago

#7688 closed bug (fixed)

:kind should do kind generalisation

Reported by: simonpj Owned by:
Priority: normal Milestone: 7.8.1
Component: Compiler Version: 7.6.2
Keywords: Cc: sheard@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case: ghci/scripts/T7688
Blocked By: Blocking:
Related Tickets: Differential Revisions:

Description

Suppose you load this into GHCi:

{-# LANGUAGE PolyKinds #-}
module Test where

data Proxy (t::k) = Proxy

Now you use :kind to see the kind of Proxy:

ghci> :k Proxy
Proxy :: * -> *

It is true that Proxy has that kind but it has a more polymorphic kind, and that's the one we'd like to see.

The trouble is this. Proxy really does have a polymorphic kind. However, :kind takes a type (not a type constructor) as its argument, so you can say

	:kind (Maybe Int)

for example. So as usual we instantiate Proxy with fresh kind variables -- BUT :kind does not do kind generalisation, so we get a monomorphic instance. (And we default unbound kind variables to *.

Conclusion: :kind should do kind-generalisation.

See also #7586

Change History (8)

comment:1 Changed 2 years ago by kosmikus

It seems to me that this is just a question of flags set in GHCi:

GHCi, version 7.6.2: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
[1 of 1] Compiling Test             ( PolyKinds.hs, interpreted )
Ok, modules loaded: Test.
*Test> :kind Proxy
Proxy :: * -> *
*Test> :set -XPolyKinds 
*Test> :kind Proxy
Proxy :: k -> *

comment:2 Changed 2 years ago by simonpj

Ha ha ha. You are quite right. GHC does kind-generalise types, but only if -XPolyKinds is on; and it's on in module Test but not at the interactive prompt.

So I'm confused by my own compiler. Advice about better UI signalling or whatever would be welcome.

comment:3 Changed 2 years ago by goldfire

I don't know how hard it would be to implement, but you could always ask the user if they intended to turn on -XPolyKinds whenever having that option on would have produced a different output than having that option off.

I've hit this problem numerous times and almost even wrote a bug report similar to yours, before I figured out what was going on. This issue is what prompted me finally to write a ghci.conf file.

comment:4 Changed 2 years ago by spl

Isn't this an instance of a general problem? GHCi does not take into account the flags in files for the prompt. I've seen this in other cases.

comment:5 follow-up: Changed 2 years ago by simonpj

  • Cc sheard@… added

The general problem is that many files are loaded, so which flags would you like to be in force?

I do wonder whether, at least for :kind, we could temporarily switch on PolyKinds, precisely to get the type generalised. That would be easy; would have no effect if the types mentioned were not themselves polykinded; and would probably lead to fewer surprises.

It's a bit ad hoc, but I think it'd be an improvement. Any other opinions?

Simon

comment:6 in reply to: ↑ 5 Changed 2 years ago by dreixel

Replying to simonpj:

I do wonder whether, at least for :kind, we could temporarily switch on PolyKinds, precisely to get the type generalised. That would be easy; would have no effect if the types mentioned were not themselves polykinded; and would probably lead to fewer surprises.

I think this is a good idea, and I couldn't come up with an example where a user might be possibly surprised at seeing unexpected polykinded stuff (since we default kinds to * when PolyKinds is off).

comment:7 Changed 2 years ago by simonpj@…

commit ed2108267b93e6abd769192bdc8fe86cefef7a70

Author: Simon Peyton Jones <[email protected]>
Date:   Fri Feb 15 17:14:36 2013 +0000

    Make :kind in GHCi do kind generalisation, always (Trac #7688)
    
    See Note [Kind-generalise in tcRnType] in TcRnDriver, and
    the notes in Trac #7688

 compiler/typecheck/TcRnDriver.lhs |   43 +++++++++++++++++++++++++------------
 1 files changed, 29 insertions(+), 14 deletions(-)

comment:8 Changed 2 years ago by simonpj

  • Resolution set to fixed
  • Status changed from new to closed
  • Test Case set to ghci/scripts/T7688

OK I did this. It's a very small change, easy to revert

Simon

Note: See TracTickets for help on using tickets.