Skip to content

Unable to newtype derive `Prim` via DerivingStrategies

The following compiles with both GHC 8.2.2 and 8.4.1:

newtype Drain = Drain { _drain :: Word8 }
  deriving stock    (Eq, Ord, Show, Generic)
  deriving newtype  (Storable)
  deriving anyclass (NFData)

However, adding Prim beside Storable in the newtype area yields the following with GHC 8.2.2:

/home/colin/code/haskell/mapalgebra/lib/Geography/MapAlgebra.hs:1148:21-24: error:
    • Illegal unboxed tuple type as function argument:
      (# ghc-prim-0.5.1.1:GHC.Prim.State# s1, Word8 #)
    • In the expression:
        ghc-prim-0.5.1.1:GHC.Prim.coerce
          @(forall (s :: TYPE ghc-prim-0.5.1.1:GHC.Types.LiftedRep).
            ghc-prim-0.5.1.1:GHC.Prim.MutableByteArray# s
            -> ghc-prim-0.5.1.1:GHC.Prim.Int#
               -> ghc-prim-0.5.1.1:GHC.Prim.State# s
                  -> (#,#) ghc-prim-0.5.1.1:GHC.Prim.State# s Word8)
          @(forall (s :: TYPE ghc-prim-0.5.1.1:GHC.Types.LiftedRep).
            ghc-prim-0.5.1.1:GHC.Prim.MutableByteArray# s
            -> ghc-prim-0.5.1.1:GHC.Prim.Int#
               -> ghc-prim-0.5.1.1:GHC.Prim.State# s
                  -> (#,#) ghc-prim-0.5.1.1:GHC.Prim.State# s Drain)
          primitive-0.6.3.0:Data.Primitive.Types.readByteArray#
      In an equation for ‘primitive-0.6.3.0:Data.Primitive.Types.readByteArray#’:
          primitive-0.6.3.0:Data.Primitive.Types.readByteArray#
            = ghc-prim-0.5.1.1:GHC.Prim.coerce
                @(forall (s :: TYPE ghc-prim-0.5.1.1:GHC.Types.LiftedRep).
                  ghc-prim-0.5.1.1:GHC.Prim.MutableByteArray# s
                  -> ghc-prim-0.5.1.1:GHC.Prim.Int#
                     -> ghc-prim-0.5.1.1:GHC.Prim.State# s
                        -> (#,#) ghc-prim-0.5.1.1:GHC.Prim.State# s Word8)
                @(forall (s :: TYPE ghc-prim-0.5.1.1:GHC.Types.LiftedRep).
                  ghc-prim-0.5.1.1:GHC.Prim.MutableByteArray# s
                  -> ghc-prim-0.5.1.1:GHC.Prim.Int#
                     -> ghc-prim-0.5.1.1:GHC.Prim.State# s
                        -> (#,#) ghc-prim-0.5.1.1:GHC.Prim.State# s Drain)

and this with GHC 8.4.1:

    Illegal kind: ((:) (ghc-prim-0.5.2.0:GHC.Types.TupleRep ([] :: [] ghc-prim-0.5.2.0:GHC.Types.RuntimeR
ep)) ((:) ghc-prim-0.5.2.0:GHC.Types.LiftedRep ([] :: [] ghc-prim-0.5.2.0:GHC.Types.RuntimeRep) :: [] 
ghc-prim-0.5.2.0:GHC.Types.RuntimeRep) :: [] ghc-prim-0.5.2.0:GHC.Types.RuntimeRep)
    Did you mean to enable TypeInType?
     |
1132 |   deriving newtype  (Storable, Prim)
     |                                

Turning on TypeInType as it suggests gives the same Illegal unboxed tuple... error.

I've hand-written Storable instances before so I'm confident in its derivation, but I otherwise know nothing about Prim. Is there something magical about it that prevents it from being newtype derived in the same way?

Thank you kindly,

Colin

Trac metadata
Trac field Value
Version 8.2.2
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