Skip to content

9.2.1 regression: GHC fails to load program with: Expected kind ‘k’, but ‘a’ has kind ‘k -> k’

Summary

GHC 9.2.1 is no longer able to compile the test program of ticket #10617 (closed).

Steps to reproduce

Load the following program (T10617) into GHCi:

{-# LANGUAGE GADTs , PolyKinds #-}

data AppTreeT (a::k) where
  Con :: AppTreeT a
  App :: AppTreeT a -> AppTreeT b -> AppTreeT (a b)

tmt :: AppTreeT (Maybe Bool)
tmt = App (Con :: AppTreeT Maybe) Con

f :: AppTreeT a -> Bool
f (App (c@Con) _) = const True c
f _ = False

This gives the following error:

roland@goms:~/Projekte/ghctest/T10617$ switchghc 9.2.1
The Glorious Glasgow Haskell Compilation System, version 9.2.1
roland@goms:~/Projekte/ghctest/T10617$ ghci T10617
GHCi, version 9.2.1: https://www.haskell.org/ghc/  :? for help
[1 of 1] Compiling Main             ( T10617.hs, interpreted )

T10617.hs:5:19: error:
    • Expected kind ‘k’, but ‘a’ has kind ‘k -> k’
    • In the first argument of ‘AppTreeT’, namely ‘a’
      In the type ‘AppTreeT a’
      In the definition of data constructor ‘App’
  |
5 |   App :: AppTreeT a -> AppTreeT b -> AppTreeT (a b)
  |                   ^
Failed, no modules loaded.

The error is independent of GHCi. When I add a main function and call plain ghc then I also see the error message.

Expected behavior

As @rae explaines below this is due to the introduction of GHC2021 in GHC 9.2.1.

The error message should contain some hints, what changes the user could try to get a program that compiles.

Circumvention

In the above program, replace the first 2 lines with

{-# LANGUAGE GADTs, StandaloneKindSignatures #-}

type AppTreeT :: forall k. k -> *
data AppTreeT a where

Environment

  • GHC version used: 9.2.1, HEAD 9.3.20211125

Optional:

  • Debian 10
  • System Architecture: x86_64
Edited by Roland Senn
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information