Skip to content

Confusing error messages with PolyKinds and superclasses

This program compiles fine:

{-# LANGUAGE FlexibleInstances #-}
import Data.Typeable

newtype Tagged t v = Tagged v
  deriving Typeable

class (Typeable t) => MyClass t where
  classF :: t -> Int

instance Typeable t => MyClass (Tagged t Int) where
  classF (Tagged n) = n

But if I add PolyKinds to the LANGUAGE pragma I get:

code/junk/typeable-problems.hs:17:10: error:
    • Could not deduce (Typeable k)
        arising from the superclasses of an instance declaration
      from the context: Typeable t
        bound by the instance declaration
        at code/junk/typeable-problems.hs:17:10-45
    • In the instance declaration for ‘MyClass (Tagged t Int)’
   |
17 | instance Typeable t => MyClass (Tagged t Int) where
   |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Which is very confusing since I don't have a k variable anywhere. Adding -fprint-explicit-kinds is somewhat better:

code/junk/typeable-problems.hs:17:10: error:
    • Could not deduce (Typeable * k)
        arising from the superclasses of an instance declaration
      from the context: Typeable k t
        bound by the instance declaration
        at code/junk/typeable-problems.hs:17:10-45
    • In the instance declaration for ‘MyClass (Tagged k t Int)’
   |
17 | instance Typeable t => MyClass (Tagged t Int) where
   |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

But still confusing. It doesn't really point me towards the solution - specifying that the kind of t is * explicitly - if I don't already know how the extension works.

It's also annoying that turning on an extension causes a type error, but I don't know if that's fixable.

Trac metadata
Trac field Value
Version 8.2.1
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information