Problem is very simple. Newtype deriving doesn't work since roles were introduced to GHC.
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeFamilies #-}
importqualifiedData.Vector.UnboxedasUimportqualifiedData.Vector.Unboxed.MutableasMUimportqualifiedData.Vector.GenericasGimportqualifiedData.Vector.Generic.MutableasGMnewtypeX=XIntnewtypeinstanceU.VectorX=V_X (U.VectorInt)
newtypeinstanceMU.MVectorsX=M_X (MU.MVectorsInt)
derivingnewtypeinstanceG.VectorU.VectorXderivingnewtypeinstanceGM.MVectorMU.MVectorXSo this simple program fails with:
• Couldn't match representation of type ‘m1 (MU.MVector
(PrimState m1) Int)’
with that of ‘m1 (MU.MVector
(PrimState m1) X)’
arising from a use of ‘GHC.Prim.coerce’
...
Reason for that are very obvious. Methods of type class has type ∀m. PrimMonad m => ... -> m a and GHC can't coerce m Int to m X because it can't assume that Int has representational/phantom role.
This problem could be fixed by changing ∀m. PrimMonad ⇒ m type parameter to ∀s. ST s. Since m only appears in positive positions both approaches are equivalent and every instance that could be written in one style could be written in another.
This is of course breaking change but breakage should be relatively limited. Type class methods are not meant to be used directly and custom instances should continue to compile
Problem is very simple. Newtype deriving doesn't work since roles were introduced to GHC.
{-# LANGUAGE DerivingStrategies #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE TypeFamilies #-} importqualifiedData.Vector.UnboxedasUimportqualifiedData.Vector.Unboxed.MutableasMUimportqualifiedData.Vector.GenericasGimportqualifiedData.Vector.Generic.MutableasGMnewtypeX=XIntnewtypeinstanceU.VectorX=V_X (U.VectorInt) newtypeinstanceMU.MVectorsX=M_X (MU.MVectorsInt) derivingnewtypeinstanceG.VectorU.VectorXderivingnewtypeinstanceGM.MVectorMU.MVectorXSo this simple program fails with:
Reason for that are very obvious. Methods of type class has type
∀m. PrimMonad m => ... -> m aand GHC can't coercem Inttom Xbecause it can't assume that Int has representational/phantom role.This problem could be fixed by changing
∀m. PrimMonad ⇒ mtype parameter to∀s. ST s. Sincemonly appears in positive positions both approaches are equivalent and every instance that could be written in one style could be written in another.This is of course breaking change but breakage should be relatively limited. Type class methods are not meant to be used directly and custom instances should continue to compile