Skip to content

CUSK-less class typechecks on 8.4, but not on 8.6+

This code will typecheck with GHC 8.0.2 through 8.4.4:

{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeInType #-}
module Bug where

import Data.Kind
import Data.Proxy

class C f where
  type T (x :: f a) :: Type

  sT :: forall a (x :: f a).
        Proxy x -> T x

However, it mysteriously does not typecheck on GHC 8.6.5 or later:

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

Bug.hs:13:22: error:
    • Expected kind ‘f a’, but ‘x’ has kind ‘f a1’
    • In the first argument of ‘T’, namely ‘x’
      In the type signature: sT :: forall a (x :: f a). Proxy x -> T x
      In the class declaration for ‘C’
   |
13 |         Proxy x -> T x
   |                      ^

I cannot think of a good reason why this shouldn't typecheck, especially since there appears to be no polymorphic recursion happening in C, T, or sT.

Some observations:

  • Giving C a CUSK (i.e., class C (f :: k -> Type) where ...) makes it typecheck:

  • Splitting up C into two classes like so also makes it typecheck:

    class C1 f where
      type T (x :: f a) :: Type
    
    class C2 f where
      sT :: forall a (x :: f a).
            Proxy x -> T x
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information