Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken GeneralizedNewtypeDeriving in ghc 7.8 #16

Closed
lostbean opened this issue Apr 15, 2014 · 4 comments

Comments

@lostbean
Copy link

commented Apr 15, 2014

Some of my code is broken with the newest version of ghc (7.8.2).

I'm using GeneralizedNewtypeDeriving to deriving instances of Data.Vector.Unbox using the following:

data VoxelPos     = VoxelPos
                    {-# UNPACK #-} !Int
                    {-# UNPACK #-} !Int
                    {-# UNPACK #-} !Int
                  deriving (Show, Eq, Ord)
newtype FacePos = FacePos VoxelPos deriving ( Eq, Hashable, NFData, G.Vector U.Vector, M.MVector U.MVector, U.Unbox)

where VoxelPos have manual rolled instances using (Int, Int, Int):

newtype instance U.MVector s VoxelPos = MV_VoxelPos (U.MVector s (Int, Int, Int))
newtype instance U.Vector    VoxelPos = V_VoxelPos  (U.Vector    (Int, Int, Int))
instance U.Unbox VoxelPos
instance M.MVector U.MVector VoxelPos where
  basicLength (MV_VoxelPos v) ...
  ...

and this was working with the previous versions of ghc. But after upgrading ghc, I get the following error:

Could not coerce from ‘U.MVector s (Int, Int, Int)’ to ‘U.MVector
                                                              s FacePos’
      because the second type argument of ‘U.MVector’ has role Nominal,
      but the arguments ‘(Int, Int, Int)’ and ‘FacePos’ differ
      arising from the coercion of the method ‘M.basicLength’ from type
                   ‘forall s. U.MVector s VoxelPos -> Int’ to type
                   ‘forall s. U.MVector s FacePos -> Int’
    Possible fix:
      use a standalone 'deriving instance' declaration,
        so you can specify the instance context yourself
    When deriving the instance for (M.MVector U.MVector FacePos)
which, I think, is because of addition of roles. I know that roles improves safety when using GeneralizedNewtypeDeriving which is, of course, really good!

What are the possible solutions to solve this?
It seems necessary to enforce the role of MVector, something like this:

type role MVector _ representational
@JohnLato

This comment has been minimized.

Copy link

commented Apr 15, 2014

I don't think this is currently fixable within vector. Role annotations
aren't allowed on type or data families currently, and I don't know any
other way to get ghc to make the coercion.

For now, I've used
http://hackage.haskell.org/package/vector-th-unbox instead of GND.
On Apr 15, 2014 4:44 AM, "Edgar Gomes" notifications@github.com wrote:

Some of my code is broken with the newest version of ghc (7.8.2).

I'm using GeneralizedNewtypeDeriving to deriving instances of
Data.Vector.Unbox using the following:

data VoxelPos = VoxelPos
{-# UNPACK #-} !Int
{-# UNPACK #-} !Int
{-# UNPACK #-} !Int
deriving (Show, Eq, Ord)

newtype FacePos = FacePos VoxelPos deriving ( Eq, Hashable, NFData, G.Vector U.Vector, M.MVector U.MVector, U.Unbox)

where VoxelPos have manual rolled instances using (Int, Int, Int):

newtype instance U.MVector s VoxelPos = MV_VoxelPos (U.MVector s (Int, Int, Int))
newtype instance U.Vector VoxelPos = V_VoxelPos (U.Vector (Int, Int, Int))
instance U.Unbox VoxelPos
instance M.MVector U.MVector VoxelPos where
basicLength (MV_VoxelPos v) ...
...

and this was working with the previous versions of ghc. But after
upgrading ghc, I get the following error:

Could not coerce from ‘U.MVector s (Int, Int, Int)’ to ‘U.MVector
s FacePos’
because the second type argument of ‘U.MVector’ has role Nominal,
but the arguments ‘(Int, Int, Int)’ and ‘FacePos’ differ
arising from the coercion of the method ‘M.basicLength’ from type
‘forall s. U.MVector s VoxelPos -> Int’ to type
‘forall s. U.MVector s FacePos -> Int’
Possible fix:
use a standalone 'deriving instance' declaration,
so you can specify the instance context yourself
When deriving the instance for (M.MVector U.MVector FacePos)
which, I think, is because of addition of roles. I know that roles improves safety when using GeneralizedNewtypeDeriving which is, of course, really good!

What are the possible solutions to solve this?
It seems necessary to enforce the role of MVector, something like this:

type role MVector _ representational


Reply to this email directly or view it on GitHubhttps://github.com//issues/16
.

@hvr

This comment has been minimized.

Copy link
Member

commented May 17, 2014

@cartazio

This comment has been minimized.

Copy link
Member

commented Feb 1, 2015

this is a ghc side problem that we can't fix in vector, and requires some future evolution of ghc's Roles tooling to enable again

@cartazio

This comment has been minimized.

Copy link
Member

commented Jul 24, 2016

closing because ghc doesn't have higher kinded roles, so we cant help GND sadness here

@cartazio cartazio closed this Jul 24, 2016

dzhus added a commit to dzhus/simple-vec3 that referenced this issue Aug 9, 2016
Use vector-th-unbox to derive Unbox UVec3 #1
GND is broken for vectors with GHC 7.8.x due to role mismatch in
associated data families (see GHC bug 9123).

Also see haskell/vector#16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.