Error message UX around CUSKs and GHC2021
GHC2021
does not enable CUSKs
, like Haskell2010
did, and so a common pattern of use will have a mysterious error message.
Consider the following module:
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TypeFamilies #-}
module Main where
type family T (a :: k) :: k where
T Char = Int
T a = a
main = pure ()
With GHC 9.0, this compiles fine:
λ ghc --version
The Glorious Glasgow Haskell Compilation System, version 9.0.1
λ ghc --make Main.hs
[1 of 1] Compiling Main ( Main.hs, Main.o )
Linking Main ...
If you upgrade to GHC 9.2, then this fails:
λ ghcup set ghc 9.2.4
[ Info ] GHC 9.2.4 successfully set as default version
λ ghc --make Main.hs
[1 of 1] Compiling Main ( Main.hs, Main.o )
Main.hs:8:5: error:
• Expected kind ‘k’, but ‘Char’ has kind ‘*’
• In the first argument of ‘T’, namely ‘Char’
In the type family declaration for ‘T’
|
8 | T Char = Int
| ^^^^
λ ghc --version
The Glorious Glasgow Haskell Compilation System, version 9.2.4
The cabal
file specifies default-language: Haskell2010
, and so cabal build
works, while ghc --make
does not.
However, suppose a project switches from Haskell2010
to GHC2021
. They'll receive those confusing error messages. I was able to diagnose this by diffing the cabal build --verbose
to get the ghc
invocation from cabal
, and noticed the -XHaskell2010
flag passed in. I checked to see what that implied, and fortunately CUSKs
was the first extension, which is the culprit.
I've never heard of CUSKs
, since it's an implied feature in the language for the entire time that I've been using it. So I had no idea that I needed an extension at all to get this behavior.
Since CUSKs
are on the Path to Deprecation and Removal, it'd be great if we could get an informative error message about the situation.
λ ghc --make Main.hs
[1 of 2] Compiling Main ( Main.hs, Main.o )
Main.hs:8:5: error:
• Expected kind ‘k’, but ‘Char’ has kind ‘*’
• In the first argument of ‘T’, namely ‘Char’
In the type family declaration for ‘T’
• The language extension `CUSKs` may fix this behavior,
but it will soon been deprecated in favor of `StandaloneKingSignatures`.
|
8 | T Char = Int
| ^^^^