Skip to content

GHC 9.0+ fails to combine levity-polymorphic newtype constructor with TypeApplications

GHC 8.10.4 has no problem typechecking this program:

{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneKindSignatures #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE UnliftedNewtypes #-}
module Bug where

import GHC.Exts

type Id :: TYPE r -> TYPE r
newtype Id a where
  MkId :: forall r (a :: TYPE r). a -> Id a

idBool :: Id Bool
idBool = MkId @LiftedRep @Bool True

However, GHC 9.0.1 and later fail with:

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

Bug.hs:17:10: error:
    • Cannot apply expression of type ‘a0 -> Id a0’
      to a visible type argument ‘LiftedRep’
    • In the expression: MkId @LiftedRep @Bool True
      In an equation for ‘idBool’: idBool = MkId @LiftedRep @Bool True
   |
17 | idBool = MkId @LiftedRep @Bool True
   |          ^^^^^^^^^^^^^^^^^^^^^^^^^^

As far as I can tell, this program should be expected to typecheck, so I believe this is a regression.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information