Skip to content

GHC 9.2 rejects certain poly-kinded unlifted newtype instances

The following program compiles on GHC 9.0, but on GHC 9.2 and HEAD it produces an error.

{-# LANGUAGE MagicHash #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE StandaloneKindSignatures #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UnboxedTuples #-}
{-# LANGUAGE UnliftedNewtypes #-}

module NewtypeInstance where

import GHC.Exts

type DF :: TYPE r
data family DF
newtype instance DF = MkDF1 Int
newtype instance DF = MkDF2 Int#
newtype instance DF = MkDF3 (# Int#, Int, Word #)
newtype instance DF = MKDF4 (# (# #) | Float# #)
NewtypeInstance.hs:15:29: error:
    * Expecting a lifted type, but `Int#' is unlifted
    * In the type `Int#'
      In the definition of data constructor `MkDF2'
      In the newtype instance declaration for `DF'
   |
15 | newtype instance DF = MkDF2 Int#
   |                             ^^^^

NewtypeInstance.hs:16:29: error:
    * Expecting a lifted type, but `(# Int#, Int, Word #)' is unlifted
    * In the type `(# Int#, Int, Word #)'
      In the definition of data constructor `MkDF3'
      In the newtype instance declaration for `DF'
   |
16 | newtype instance DF = MkDF3 (# Int#, Int, Word #)
   |                             ^^^^^^^^^^^^^^^^^^^^^

NewtypeInstance.hs:17:29: error:
    * Expecting a lifted type, but `(# (# #) | Float# #)' is unlifted
    * In the type `(# (# #) | Float# #)'
      In the definition of data constructor `MKDF4'
      In the newtype instance declaration for `DF'
   |
17 | newtype instance DF = MKDF4 (# (# #) | Float# #)
   |                             ^^^^^^^^^^^^^^^^^^^^

I think the program should be accepted: we have an invisible kind argument which is taking a different value in each newtype instance. For some reason, starting with GHC 9.2, some defaulting seems to take place and we start expecting r to be LiftedRep.

I'm not sure what has caused the change in behaviour. Pinging the experts @rae and @RyanGlScott.

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