Skip to content

GHC requires PolyKinds in places without any kind polymorphism

I would expect the following to typecheck:

{-# LANGUAGE DataKinds #-}
{-# LANGUAGE KindSignatures #-}
module Bug where

import Data.Kind
import Data.Proxy

data T :: Proxy 0 -> Type

Surprisingly, however, it doesn't.

$ /opt/ghc/8.10.2/bin/ghc Bug.hs
[1 of 1] Compiling Bug              ( Bug.hs, Bug.o )

Bug.hs:8:17: error:
    Illegal kind: 0
    Did you mean to enable PolyKinds?
  |
8 | data T :: Proxy 0 -> Type
  |                 ^

I find it quite surprising that using a type-level literal would require PolyKinds, as there's nothing inherently poly-kinded about it.

This isn't even the only example of strange PolyKinds requirements. The following programs are also rejected for similar reasons:

  • Kind-level uses of =>:

    {-# LANGUAGE DataKinds #-}
    {-# LANGUAGE KindSignatures #-}
    module Bug where
    
    import Data.Kind
    
    data T :: () => Type
    $ /opt/ghc/8.10.2/bin/ghc Bug.hs
    [1 of 1] Compiling Bug              ( Bug.hs, Bug.o )
    
    Bug.hs:7:11: error:
        Illegal kind: () => Type
        Did you mean to enable PolyKinds?
      |
    7 | data T :: () => Type
      |           ^^^^^^^^^^
  • Kind-level uses of explicit annotations:

    {-# LANGUAGE DataKinds #-}
    {-# LANGUAGE KindSignatures #-}
    module Bug where
    
    import Data.Kind
    
    data T :: (Type :: Type) -> Type
    $ /opt/ghc/8.10.2/bin/ghc Bug.hs
    [1 of 1] Compiling Bug              ( Bug.hs, Bug.o )
    
    Bug.hs:7:12: error:
        Illegal kind: Type :: Type
        Did you mean to enable PolyKinds?
      |
    7 | data T :: (Type :: Type) -> Type
      |            ^^^^^^^^^^^^
  • Kind-level uses of promoted lists:

    {-# LANGUAGE DataKinds #-}
    {-# LANGUAGE KindSignatures #-}
    module Bug where
    
    import Data.Kind
    import Data.Proxy
    
    data T :: Proxy '[Type,Type] -> Type
    $ /opt/ghc/8.10.2/bin/ghc Bug.hs
    [1 of 1] Compiling Bug              ( Bug.hs, Bug.o )
    
    Bug.hs:8:17: error:
        Illegal kind: '[Type, Type]
        Did you mean to enable PolyKinds?
      |
    8 | data T :: Proxy '[Type,Type] -> Type
      |                 ^^^^^^^^^^^^
  • Kind-level uses of promoted tuples:

    {-# LANGUAGE DataKinds #-}
    {-# LANGUAGE KindSignatures #-}
    module Bug where
    
    import Data.Kind
    import Data.Proxy
    
    data T :: Proxy '(Type,Type) -> Type
    $ /opt/ghc/8.10.2/bin/ghc Bug.hs
    [1 of 1] Compiling Bug              ( Bug.hs, Bug.o )
    
    Bug.hs:8:17: error:
        Illegal kind: '(Type, Type)
        Did you mean to enable PolyKinds?
      |
    8 | data T :: Proxy '(Type,Type) -> Type
      |                 ^^^^^^^^^^^^
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information