Skip to content

Error with -XPolyKinds and -XDerivingVia

Summary

I get a strange GHC panic error running the following program:

Steps to reproduce

mateusz@mateusz-thinkpad:~/test$ cat Test.hs
{-# LANGUAGE PolyKinds, DerivingVia, StandaloneKindSignatures #-}

module Main where

import Data.IORef
import Control.Monad.IO.Class
import Control.Monad.Reader
import Data.Kind

--type StateTIO :: Type -> (Type -> Type) -> Type -> Type
newtype StateTIO s m a = StateTIO { runStateTIO :: IORef s -> m a }
  deriving (Functor, Applicative, Monad, MonadIO) via ReaderT (IORef s) m

main :: IO ()
main = pure ()

mateusz@mateusz-thinkpad:~/test$ runhaskell Test.hs 

Test.hs:12:73: error:ghc: panic! (the 'impossible' happened)
  (GHC version 9.2.5:
	No skolem info:
  [k_aGC]
  Call stack:
      CallStack (from HasCallStack):
        callStackDoc, called at compiler/GHC/Utils/Panic.hs:181:37 in ghc:GHC.Utils.Panic
        pprPanic, called at compiler/GHC/Tc/Errors.hs:2912:17 in ghc:GHC.Tc.Errors

Please report this as a GHC bug:  https://www.haskell.org/ghc/reportabug

Also throws the same error when compiling.

Expected behavior

GHC should complain about kind of m:

Main.hs:18:73: error:
    • Couldn't match kind ‘k’ with ‘*’
      Expected kind ‘* -> *’, but ‘m’ has kind ‘k -> *’
    • In the second argument of ‘ReaderT’, namely ‘m’
      In the newtype declaration for ‘StateTIO’
   |
18 |   deriving (Functor, Applicative, Monad, MonadIO) via ReaderT (IORef s) m
   |                                                                         ^

works this way both on 8.10.7 and 9.0.2. It compiles (on both versions and on 9.2.5) when I either remove the comment specifying the kind, or remove -XPolyKinds extension.

Environment

  • GHC version used: 9.2.5

Optional:

  • Operating System: Ubuntu 22.04
  • System Architecture: x86_64
Edited by Mateusz Goślinowski
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information