일부 코드는 ghc 7.8.2의 최신 버전으로 인해 손상되었습니다. 내가 사용 Data.Vector.Unbox
의 파생 인스턴스에 GeneralizedNewtypeDeriving
을 사용하고GHC에서 역할이 깨진 코드 7.8
다음 VoxelPos
수동이
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)
는 (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) ...
...
을 그리고 이것은 이전 버전의 작업을했다 ghc. 그러나 ghc를 업그레이드 한 후에 다음과 같은 오류가 발생합니다.
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)
나는 생각하기에 역할 추가 때문입니다. 나는 역할이 안전을 향상 시킨다는 것을 알고 있습니다. GeneralizedNewtypeDeriving
은 물론, 정말 좋습니다!
해결 방법은 무엇입니까? 가장 권장되는 것은 무엇입니까?
docs (http://www.haskell.org/ghc/docs/7.8.2/html/users_guide/roles.html)에 따르면 데이터 유형의 역할을 변경해야하지만 데이터 유형의 정의에서만 수행 할 수 있습니다. 데이터 패밀리와 역할이 어떻게 상호 작용하는지 잘 모르겠습니다. 인스턴스별로 역할을 정의 할 수 있습니다. 그러나 나는 의심합니다. – user2407038
그러나 ' MVector' 나는'vector' 라이브러리에서 이것을 변경해야합니다. 아마도'vector' 패키지의 관리자에게보고해야 할 것입니다. – LambdaStaal