Skip to content

GHCi :info uses an outdated mechanism to show type synonym arity

Current GHCi behavior:

ghci> type T = Maybe
ghci> :i T
type T :: * -> *
type T = Maybe :: * -> *
  	-- Defined at <interactive>:24:1

I expect to see type T = Maybe without the * -> * annotation, which is redundant: there's a standalone kind signature on the preceding line.

Historical remark

Such annotations were not wholly redundant in the past, as they could influence arity inference. Compare, for example

ghci> type T0 :: forall k. k -> Type; type T0 = Proxy :: forall k. k -> Type
ghci> type T1 :: forall k. k -> Type; type T1 = Proxy

GHC 9.6 assigns different arities to T0 and T1:

ghci> :i T0
type T0 :: forall k. k -> *
type T0 = Proxy :: forall k. k -> *
  	-- Defined at <interactive>:4:33
ghci> :i T1
type T1 :: forall k. k -> *
type T1 = Proxy :: k -> *
  	-- Defined at <interactive>:5:33

However, this arcane mechanism has been removed in e89aa072. Here's what GHC HEAD has to say about these declarations:

ghci> :i T0
type T0 :: forall k. k -> *
type T0 = Proxy :: forall k. k -> *
  	-- Defined at <interactive>:4:33
ghci> :i T1
type T1 :: forall k. k -> *
type T1 = Proxy :: forall k. k -> *
  	-- Defined at <interactive>:5:33

That is, they are equivalent. The modern mechanism for controlling arity is the use of @-binders.

Current status

The pretty-printer has not been updated to use @-binders. Consider this GHCi session (GHC HEAD)

ghci> :set -XTypeAbstractions 
ghci> type T2 :: forall k. k -> Type; type T2 @k = Proxy
ghci> :i T2
type T2 :: forall k. k -> *
type T2 = Proxy :: k -> *
  	-- Defined at <interactive>:5:33

The arity of the printed declaration is not equivalent to the user-written declaration. It should use @k to include the kind variable in the arity: type T2 @k = Proxy.

(A further complication is that the printed example triggers a panic, see #24470 (closed)).

Proposed fix

  1. In the pretty-printer, omit the redundant kind annotation on the RHS of type synonyms
  2. In the pretty-printer, use @-binders to control the arity

Also, I've only checked type synonyms. There might be similar issues affecting type families.

Edited by Vladislav Zavialov
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information