3
这个工作在GHC 7.8.4罚款,但未能在7.10.3:NEWTYPE与GHC 7.10
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Foo where
import qualified Data.Array.Unboxed as A
import GHC.Generics (Generic)
newtype Elt = Elt Int deriving (Eq, Ord, Show, Num, Integral, Real, Enum, A.IArray A.UArray, Generic)
type MyArr = A.UArray Int Elt
有大量的消息像
/tmp/my.hs:9:75:
Couldn't match type ‘Int’ with ‘Elt’
arising from the coercion of the method ‘Data.Array.Base.numElements’
from type ‘forall i. A.Ix i => A.UArray i Int -> Int’
to type ‘forall i. A.Ix i => A.UArray i Elt -> Int’
Relevant role signatures:
type role A.Ix nominal
type role A.UArray nominal nominal
When deriving the instance for (A.IArray A.UArray Elt)
虽然7.10的发布说明没有提到它,我看到 https://ghc.haskell.org/trac/ghc/ticket/9220#comment:11承认其突破性的变化。但是,解决方案是什么 - 我是否真的必须为MyArr创建一个新类型的包装器,并为每种用法使用辅助函数?
有趣。也许'UArray'从元素的表现转化为名义角色?我想知道为什么。 – chi
是的,看起来像你会(另一个'vector'的参数 - 获得'UnBox'实例更容易)。即使你想通过'IArray UArray Elt'实例'unsafeCoerce',你也不能导出你需要实现的方法。虽然我明白为什么我们不应该在这里接地,但我们无法手写我们的'IArray'实例的事实让我有点不高兴...... – Alec
您可以从'Data.Array.Base'中导入方法。 –