Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#9018 closed feature request (fixed)

GHC suppresses too much kind information

Reported by: simonpj Owned by:
Priority: normal Milestone: 7.8.3
Component: Compiler Version: 7.8.2
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


GHC tends to hide important kind polymorphism in error messages and in GHCi. (I came across this when looking at #9017.) For example, try this:

bash$ cat Test.hs
{-# LANGUAGE PolyKinds #-}
module Test where
foo :: m a
foo = foo

bash$ ghci Test.hs
ghci> :t foo
foo :: m a
ghci> :i foo
foo :: m a

bash$ ghci Test.hs -XPolyKinds
ghci> :t foo
foo :: m a
ghci> :i foo
goo :: m a

bash$ ghci Test.hs -fprint-explicit-foralls -fprint-explicit-kinds
ghci> :t foo
foo :: foo :: forall (m :: * -> *) d. m d
ghci> :i foo
foo :: forall (k :: BOX) (m :: k -> *) (d :: k). m d

bash$ ghci Test.hs -XPolyKinds -fprint-explicit-foralls -fprint-explicit-kinds
ghci> :t foo
foo :: forall (k :: BOX) (m :: k -> *) (d :: k). m d
ghci> :i foo
foo :: forall (k :: BOX) (m :: k -> *) (d :: k). m d

Pretty confusing eh?

  • Without -fprint-explicit-foralls -fprint-explicit-kinds you don't see the kinds on the types at all.
  • Without -XPolyKinds in GHCi, when you say :t foo you are asking for the type of the expression foo (it could be an arbitrary expression). So foo is instantiated and then re-generalised; but without -XPolyKinds we don't get a poly-kinded type. Hence the difference in what is printed by :type and :info.

Here's a proposal: even without -fprint-explicit-foralls, we should print any foralls that bind a type variable whose kind includes a kind variable.

Change History (4)

comment:1 Changed 2 years ago by goldfire

+1 from me.

I lived without a .ghci file until I experienced pain from this particular issue. Now, I have

:seti -XPolyKinds
:set -fprint-explicit-foralls
:set -fprint-explicit-kinds

among other options.

Perhaps it might also be nice to inform the user to use -fprint-explicit-kinds in an error message if some heuristics (don't know what, at the moment) indicate that it might be helpful. I feel like I've answered several invalid bug reports because of quite legitimately confusing error messages.

comment:2 Changed 2 years ago by Simon Peyton Jones <simonpj@…>

In 2f3ea95285d0cccc2a999e7572d8fb78dc2ea441/ghc:

Print for-alls more often (Trac #9018)

We now display the foralls of a type if any of the type variables
is polykinded.  This put kind polymorphism "in your face" a bit more
often, but eliminates a lot of head scratching.

The user manual reflects the new behaviour.

comment:3 Changed 2 years ago by simonpj

  • Resolution set to fixed
  • Status changed from new to closed

comment:4 Changed 2 years ago by thoughtpolice

  • Milestone set to 7.8.3

This was merged into GHC 7.8 for 7.8.3 (part of fixing #9175).

Note: See TracTickets for help on using tickets.