这个程序:
{-# LANGUAGE MultiParamTypeClasses, TemplateHaskell, TypeFamilies #-}
import Data.Vector.Unboxed.Deriving
data Node = Node Int Int Int Int Int Int Int deriving (Show)
derivingUnbox "Node"
[t| Node -> (Int, Int, Int, Int, Int, Int, Int) |]
[| \ (Node a b c d e f g) -> (a,b,c,d,e,f,g) |]
[| \ (a,b,c,d,e,f,g) -> Node a b c d e f g |]
main = print 7
无法编译,出现此错误消息:
debox_error.hs:6:1:
No instance for (Data.Vector.Generic.Base.Vector
Data.Vector.Unboxed.Base.Vector
(Int, Int, Int, Int, Int, Int, Int))
arising from a use of ‘Data.Vector.Generic.Base.basicLength’
In the expression: Data.Vector.Generic.Base.basicLength vec_a320
In an equation for ‘basicLength’:
basicLength (V_Node vec_a320)
= Data.Vector.Generic.Base.basicLength vec_a320
In the instance declaration for
‘Data.Vector.Generic.Base.Vector
Data.Vector.Unboxed.Base.Vector Node’
debox_error.hs:6:1:
Could not deduce (Data.Vector.Generic.Base.Vector
Data.Vector.Unboxed.Base.Vector
(Int, Int, Int, Int, Int, Int, Int))
arising from a use of ‘Data.Vector.Generic.Base.basicUnsafeFreeze’
from the context (Control.Monad.Primitive.PrimMonad m)
bound by the type signature for
basicUnsafeFreeze :: Control.Monad.Primitive.PrimMonad m =>
Data.Vector.Generic.Base.Mutable
Data.Vector.Unboxed.Base.Vector
(Control.Monad.Primitive.PrimState m)
Node
-> m (Data.Vector.Unboxed.Base.Vector Node)
at debox_error.hs:(6,1)-(9,49)
In the second argument of ‘Control.Monad.liftM’, namely
‘(Data.Vector.Generic.Base.basicUnsafeFreeze mvec_a31Y)’
In the expression:
(V_Node
`Control.Monad.liftM`
(Data.Vector.Generic.Base.basicUnsafeFreeze mvec_a31Y))
In an equation for ‘basicUnsafeFreeze’:
basicUnsafeFreeze (MV_Node mvec_a31Y)
= (V_Node
`Control.Monad.liftM`
(Data.Vector.Generic.Base.basicUnsafeFreeze mvec_a31Y))
debox_error.hs:6:1:
Could not deduce (Data.Vector.Generic.Base.Vector
Data.Vector.Unboxed.Base.Vector
(Int, Int, Int, Int, Int, Int, Int))
arising from a use of ‘Data.Vector.Generic.Base.basicUnsafeThaw’
from the context (Control.Monad.Primitive.PrimMonad m)
bound by the type signature for
basicUnsafeThaw :: Control.Monad.Primitive.PrimMonad m =>
Data.Vector.Unboxed.Base.Vector Node
-> m (Data.Vector.Generic.Base.Mutable
Data.Vector.Unboxed.Base.Vector
(Control.Monad.Primitive.PrimState m)
Node)
at debox_error.hs:(6,1)-(9,49)
In the second argument of ‘Control.Monad.liftM’, namely
‘(Data.Vector.Generic.Base.basicUnsafeThaw vec_a320)’
In the expression:
(MV_Node
`Control.Monad.liftM`
(Data.Vector.Generic.Base.basicUnsafeThaw vec_a320))
In an equation for ‘basicUnsafeThaw’:
basicUnsafeThaw (V_Node vec_a320)
= (MV_Node
`Control.Monad.liftM`
(Data.Vector.Generic.Base.basicUnsafeThaw vec_a320))
debox_error.hs:6:1:
Could not deduce (Data.Vector.Generic.Base.Vector
Data.Vector.Unboxed.Base.Vector
(Int, Int, Int, Int, Int, Int, Int))
arising from a use of ‘Data.Vector.Generic.Base.basicUnsafeIndexM’
from the context (Monad m)
bound by the type signature for
basicUnsafeIndexM :: Monad m =>
Data.Vector.Unboxed.Base.Vector Node -> Int -> m Node
at debox_error.hs:(6,1)-(9,49)
In the second argument of ‘Control.Monad.liftM’, namely
‘(Data.Vector.Generic.Base.basicUnsafeIndexM vec_a320 idx_a31W)’
In the expression:
((\ (a_a328, b_a329, c_a32a, d_a32b, e_a32c, f_a32d, g_a32e)
-> Node a_a328 b_a329 c_a32a d_a32b e_a32c f_a32d g_a32e)
`Control.Monad.liftM`
(Data.Vector.Generic.Base.basicUnsafeIndexM vec_a320 idx_a31W))
In an equation for ‘basicUnsafeIndexM’:
basicUnsafeIndexM (V_Node vec_a320) idx_a31W
= ((\ (a_a328, b_a329, c_a32a, d_a32b, e_a32c, f_a32d, g_a32e)
-> Node a_a328 b_a329 c_a32a d_a32b e_a32c f_a32d g_a32e)
`Control.Monad.liftM`
(Data.Vector.Generic.Base.basicUnsafeIndexM vec_a320 idx_a31W))
debox_error.hs:6:1:
Could not deduce (Data.Vector.Generic.Base.Vector
Data.Vector.Unboxed.Base.Vector
(Int, Int, Int, Int, Int, Int, Int))
arising from a use of ‘Data.Vector.Generic.Base.basicUnsafeCopy’
from the context (Control.Monad.Primitive.PrimMonad m)
bound by the type signature for
basicUnsafeCopy :: Control.Monad.Primitive.PrimMonad m =>
Data.Vector.Generic.Base.Mutable
Data.Vector.Unboxed.Base.Vector
(Control.Monad.Primitive.PrimState m)
Node
-> Data.Vector.Unboxed.Base.Vector Node -> m ()
at debox_error.hs:(6,1)-(9,49)
In the expression:
Data.Vector.Generic.Base.basicUnsafeCopy mvec_a31Y vec_a320
In an equation for ‘basicUnsafeCopy’:
basicUnsafeCopy (MV_Node mvec_a31Y) (V_Node vec_a320)
= Data.Vector.Generic.Base.basicUnsafeCopy mvec_a31Y vec_a320
In the instance declaration for
‘Data.Vector.Generic.Base.Vector
Data.Vector.Unboxed.Base.Vector Node’
debox_error.hs:6:1:
No instance for (Data.Vector.Generic.Base.Vector
Data.Vector.Unboxed.Base.Vector
(Int, Int, Int, Int, Int, Int, Int))
arising from a use of ‘Data.Vector.Generic.Base.elemseq’
In the expression:
Data.Vector.Generic.Base.elemseq
vec_a320
(\ (Node a_a321 b_a322 c_a323 d_a324 e_a325 f_a326 g_a327)
-> (a_a321, b_a322, c_a323, d_a324, e_a325, f_a326, g_a327)
val_a32f)
In an equation for ‘elemseq’:
elemseq (V_Node vec_a320) val_a32f
= Data.Vector.Generic.Base.elemseq
vec_a320
(\ (Node a_a321 b_a322 c_a323 d_a324 e_a325 f_a326 g_a327)
-> (a_a321, b_a322, c_a323, d_a324, e_a325, f_a326, g_a327)
val_a32f)
In the instance declaration for
‘Data.Vector.Generic.Base.Vector
Data.Vector.Unboxed.Base.Vector Node’
debox_error.hs:6:1:
No instance for (Data.Vector.Generic.Mutable.MVector
Data.Vector.Unboxed.Base.MVector
(Int, Int, Int, Int, Int, Int, Int))
arising from a use of ‘Data.Vector.Generic.Mutable.basicLength’
In the expression:
Data.Vector.Generic.Mutable.basicLength mvec_a31Y
In an equation for ‘basicLength’:
basicLength (MV_Node mvec_a31Y)
= Data.Vector.Generic.Mutable.basicLength mvec_a31Y
In the instance declaration for
‘Data.Vector.Generic.Mutable.MVector
Data.Vector.Unboxed.Base.MVector Node’
debox_error.hs:6:1:
No instance for (Data.Vector.Generic.Mutable.MVector
Data.Vector.Unboxed.Base.MVector
(Int, Int, Int, Int, Int, Int, Int))
arising from a use of ‘Data.Vector.Generic.Mutable.basicUnsafeSlice’
In the first argument of ‘MV_Node’, namely
‘Data.Vector.Generic.Mutable.basicUnsafeSlice
idx_a31W len_a31X mvec_a31Y’
In the expression:
MV_Node
(Data.Vector.Generic.Mutable.basicUnsafeSlice
idx_a31W len_a31X mvec_a31Y)
In an equation for ‘basicUnsafeSlice’:
basicUnsafeSlice idx_a31W len_a31X (MV_Node mvec_a31Y)
= MV_Node
(Data.Vector.Generic.Mutable.basicUnsafeSlice
idx_a31W len_a31X mvec_a31Y)
debox_error.hs:6:1:
No instance for (Data.Vector.Generic.Mutable.MVector
Data.Vector.Unboxed.Base.MVector
(Int, Int, Int, Int, Int, Int, Int))
arising from a use of ‘Data.Vector.Generic.Mutable.basicOverlaps’
In the expression:
Data.Vector.Generic.Mutable.basicOverlaps mvec_a31Y mvec'_a31Z
In an equation for ‘basicOverlaps’:
basicOverlaps (MV_Node mvec_a31Y) (MV_Node mvec'_a31Z)
= Data.Vector.Generic.Mutable.basicOverlaps mvec_a31Y mvec'_a31Z
In the instance declaration for
‘Data.Vector.Generic.Mutable.MVector
Data.Vector.Unboxed.Base.MVector Node’
debox_error.hs:6:1:
Could not deduce (Data.Vector.Generic.Mutable.MVector
Data.Vector.Unboxed.Base.MVector
(Int, Int, Int, Int, Int, Int, Int))
arising from a use of ‘Data.Vector.Generic.Mutable.basicUnsafeNew’
from the context (Control.Monad.Primitive.PrimMonad m)
bound by the type signature for
basicUnsafeNew :: Control.Monad.Primitive.PrimMonad m =>
Int
-> m (Data.Vector.Unboxed.Base.MVector
(Control.Monad.Primitive.PrimState m) Node)
at debox_error.hs:(6,1)-(9,49)
In the second argument of ‘Control.Monad.liftM’, namely
‘(Data.Vector.Generic.Mutable.basicUnsafeNew len_a31X)’
In the expression:
(MV_Node
`Control.Monad.liftM`
(Data.Vector.Generic.Mutable.basicUnsafeNew len_a31X))
In an equation for ‘basicUnsafeNew’:
basicUnsafeNew len_a31X
= (MV_Node
`Control.Monad.liftM`
(Data.Vector.Generic.Mutable.basicUnsafeNew len_a31X))
debox_error.hs:6:1:
Could not deduce (Data.Vector.Generic.Mutable.MVector
Data.Vector.Unboxed.Base.MVector
(Int, Int, Int, Int, Int, Int, Int))
arising from a use of ‘Data.Vector.Generic.Mutable.basicUnsafeReplicate’
from the context (Control.Monad.Primitive.PrimMonad m)
bound by the type signature for
basicUnsafeReplicate :: Control.Monad.Primitive.PrimMonad m =>
Int
-> Node
-> m (Data.Vector.Unboxed.Base.MVector
(Control.Monad.Primitive.PrimState m) Node)
at debox_error.hs:(6,1)-(9,49)
In the second argument of ‘Control.Monad.liftM’, namely
‘(Data.Vector.Generic.Mutable.basicUnsafeReplicate
len_a31X
(\ (Node a_a321 b_a322 c_a323 d_a324 e_a325 f_a326 g_a327)
-> (a_a321, b_a322, c_a323, d_a324, e_a325, f_a326, g_a327)
val_a32f))’
In the expression:
(MV_Node
`Control.Monad.liftM`
(Data.Vector.Generic.Mutable.basicUnsafeReplicate
len_a31X
(\ (Node a_a321 b_a322 c_a323 d_a324 e_a325 f_a326 g_a327)
-> (a_a321, b_a322, c_a323, d_a324, e_a325, f_a326, g_a327)
val_a32f)))
In an equation for ‘basicUnsafeReplicate’:
basicUnsafeReplicate len_a31X val_a32f
= (MV_Node
`Control.Monad.liftM`
(Data.Vector.Generic.Mutable.basicUnsafeReplicate
len_a31X
(\ (Node a_a321 b_a322 c_a323 d_a324 e_a325 f_a326 g_a327)
-> (a_a321, b_a322, c_a323, d_a324, e_a325, f_a326, g_a327)
val_a32f)))
debox_error.hs:6:1:
Could not deduce (Data.Vector.Generic.Mutable.MVector
Data.Vector.Unboxed.Base.MVector
(Int, Int, Int, Int, Int, Int, Int))
arising from a use of ‘Data.Vector.Generic.Mutable.basicUnsafeRead’
from the context (Control.Monad.Primitive.PrimMonad m)
bound by the type signature for
basicUnsafeRead :: Control.Monad.Primitive.PrimMonad m =>
Data.Vector.Unboxed.Base.MVector
(Control.Monad.Primitive.PrimState m) Node
-> Int -> m Node
at debox_error.hs:(6,1)-(9,49)
In the second argument of ‘Control.Monad.liftM’, namely
‘(Data.Vector.Generic.Mutable.basicUnsafeRead mvec_a31Y idx_a31W)’
In the expression:
((\ (a_a328, b_a329, c_a32a, d_a32b, e_a32c, f_a32d, g_a32e)
-> Node a_a328 b_a329 c_a32a d_a32b e_a32c f_a32d g_a32e)
`Control.Monad.liftM`
(Data.Vector.Generic.Mutable.basicUnsafeRead mvec_a31Y idx_a31W))
In an equation for ‘basicUnsafeRead’:
basicUnsafeRead (MV_Node mvec_a31Y) idx_a31W
= ((\ (a_a328, b_a329, c_a32a, d_a32b, e_a32c, f_a32d, g_a32e)
-> Node a_a328 b_a329 c_a32a d_a32b e_a32c f_a32d g_a32e)
`Control.Monad.liftM`
(Data.Vector.Generic.Mutable.basicUnsafeRead mvec_a31Y idx_a31W))
debox_error.hs:6:1:
Could not deduce (Data.Vector.Generic.Mutable.MVector
Data.Vector.Unboxed.Base.MVector
(Int, Int, Int, Int, Int, Int, Int))
arising from a use of ‘Data.Vector.Generic.Mutable.basicUnsafeWrite’
from the context (Control.Monad.Primitive.PrimMonad m)
bound by the type signature for
basicUnsafeWrite :: Control.Monad.Primitive.PrimMonad m =>
Data.Vector.Unboxed.Base.MVector
(Control.Monad.Primitive.PrimState m) Node
-> Int -> Node -> m ()
at debox_error.hs:(6,1)-(9,49)
In the expression:
Data.Vector.Generic.Mutable.basicUnsafeWrite
mvec_a31Y
idx_a31W
(\ (Node a_a321 b_a322 c_a323 d_a324 e_a325 f_a326 g_a327)
-> (a_a321, b_a322, c_a323, d_a324, e_a325, f_a326, g_a327)
val_a32f)
In an equation for ‘basicUnsafeWrite’:
basicUnsafeWrite (MV_Node mvec_a31Y) idx_a31W val_a32f
= Data.Vector.Generic.Mutable.basicUnsafeWrite
mvec_a31Y
idx_a31W
(\ (Node a_a321 b_a322 c_a323 d_a324 e_a325 f_a326 g_a327)
-> (a_a321, b_a322, c_a323, d_a324, e_a325, f_a326, g_a327)
val_a32f)
In the instance declaration for
‘Data.Vector.Generic.Mutable.MVector
Data.Vector.Unboxed.Base.MVector Node’
debox_error.hs:6:1:
Could not deduce (Data.Vector.Generic.Mutable.MVector
Data.Vector.Unboxed.Base.MVector
(Int, Int, Int, Int, Int, Int, Int))
arising from a use of ‘Data.Vector.Generic.Mutable.basicClear’
from the context (Control.Monad.Primitive.PrimMonad m)
bound by the type signature for
basicClear :: Control.Monad.Primitive.PrimMonad m =>
Data.Vector.Unboxed.Base.MVector
(Control.Monad.Primitive.PrimState m) Node
-> m ()
at debox_error.hs:(6,1)-(9,49)
In the expression: Data.Vector.Generic.Mutable.basicClear mvec_a31Y
In an equation for ‘basicClear’:
basicClear (MV_Node mvec_a31Y)
= Data.Vector.Generic.Mutable.basicClear mvec_a31Y
In the instance declaration for
‘Data.Vector.Generic.Mutable.MVector
Data.Vector.Unboxed.Base.MVector Node’
debox_error.hs:6:1:
Could not deduce (Data.Vector.Generic.Mutable.MVector
Data.Vector.Unboxed.Base.MVector
(Int, Int, Int, Int, Int, Int, Int))
arising from a use of ‘Data.Vector.Generic.Mutable.basicSet’
from the context (Control.Monad.Primitive.PrimMonad m)
bound by the type signature for
basicSet :: Control.Monad.Primitive.PrimMonad m =>
Data.Vector.Unboxed.Base.MVector
(Control.Monad.Primitive.PrimState m) Node
-> Node -> m ()
at debox_error.hs:(6,1)-(9,49)
In the expression:
Data.Vector.Generic.Mutable.basicSet
mvec_a31Y
(\ (Node a_a321 b_a322 c_a323 d_a324 e_a325 f_a326 g_a327)
-> (a_a321, b_a322, c_a323, d_a324, e_a325, f_a326, g_a327)
val_a32f)
In an equation for ‘basicSet’:
basicSet (MV_Node mvec_a31Y) val_a32f
= Data.Vector.Generic.Mutable.basicSet
mvec_a31Y
(\ (Node a_a321 b_a322 c_a323 d_a324 e_a325 f_a326 g_a327)
-> (a_a321, b_a322, c_a323, d_a324, e_a325, f_a326, g_a327)
val_a32f)
In the instance declaration for
‘Data.Vector.Generic.Mutable.MVector
Data.Vector.Unboxed.Base.MVector Node’
debox_error.hs:6:1:
Could not deduce (Data.Vector.Generic.Mutable.MVector
Data.Vector.Unboxed.Base.MVector
(Int, Int, Int, Int, Int, Int, Int))
arising from a use of ‘Data.Vector.Generic.Mutable.basicUnsafeCopy’
from the context (Control.Monad.Primitive.PrimMonad m)
bound by the type signature for
basicUnsafeCopy :: Control.Monad.Primitive.PrimMonad m =>
Data.Vector.Unboxed.Base.MVector
(Control.Monad.Primitive.PrimState m) Node
-> Data.Vector.Unboxed.Base.MVector
(Control.Monad.Primitive.PrimState m) Node
-> m ()
at debox_error.hs:(6,1)-(9,49)
In the expression:
Data.Vector.Generic.Mutable.basicUnsafeCopy mvec_a31Y mvec'_a31Z
In an equation for ‘basicUnsafeCopy’:
basicUnsafeCopy (MV_Node mvec_a31Y) (MV_Node mvec'_a31Z)
= Data.Vector.Generic.Mutable.basicUnsafeCopy mvec_a31Y mvec'_a31Z
In the instance declaration for
‘Data.Vector.Generic.Mutable.MVector
Data.Vector.Unboxed.Base.MVector Node’
debox_error.hs:6:1:
Could not deduce (Data.Vector.Generic.Mutable.MVector
Data.Vector.Unboxed.Base.MVector
(Int, Int, Int, Int, Int, Int, Int))
arising from a use of ‘Data.Vector.Generic.Mutable.basicUnsafeMove’
from the context (Control.Monad.Primitive.PrimMonad m)
bound by the type signature for
basicUnsafeMove :: Control.Monad.Primitive.PrimMonad m =>
Data.Vector.Unboxed.Base.MVector
(Control.Monad.Primitive.PrimState m) Node
-> Data.Vector.Unboxed.Base.MVector
(Control.Monad.Primitive.PrimState m) Node
-> m ()
at debox_error.hs:(6,1)-(9,49)
In the expression:
Data.Vector.Generic.Mutable.basicUnsafeMove mvec_a31Y mvec'_a31Z
In an equation for ‘basicUnsafeMove’:
basicUnsafeMove (MV_Node mvec_a31Y) (MV_Node mvec'_a31Z)
= Data.Vector.Generic.Mutable.basicUnsafeMove mvec_a31Y mvec'_a31Z
In the instance declaration for
‘Data.Vector.Generic.Mutable.MVector
Data.Vector.Unboxed.Base.MVector Node’
debox_error.hs:6:1:
Could not deduce (Data.Vector.Generic.Mutable.MVector
Data.Vector.Unboxed.Base.MVector
(Int, Int, Int, Int, Int, Int, Int))
arising from a use of ‘Data.Vector.Generic.Mutable.basicUnsafeGrow’
from the context (Control.Monad.Primitive.PrimMonad m)
bound by the type signature for
basicUnsafeGrow :: Control.Monad.Primitive.PrimMonad m =>
Data.Vector.Unboxed.Base.MVector
(Control.Monad.Primitive.PrimState m) Node
-> Int
-> m (Data.Vector.Unboxed.Base.MVector
(Control.Monad.Primitive.PrimState m) Node)
at debox_error.hs:(6,1)-(9,49)
In the second argument of ‘Control.Monad.liftM’, namely
‘(Data.Vector.Generic.Mutable.basicUnsafeGrow mvec_a31Y len_a31X)’
In the expression:
(MV_Node
`Control.Monad.liftM`
(Data.Vector.Generic.Mutable.basicUnsafeGrow mvec_a31Y len_a31X))
In an equation for ‘basicUnsafeGrow’:
basicUnsafeGrow (MV_Node mvec_a31Y) len_a31X
= (MV_Node
`Control.Monad.liftM`
(Data.Vector.Generic.Mutable.basicUnsafeGrow mvec_a31Y len_a31X))
如何解决此问题?
答案 0 :(得分:8)
我相信这是因为vector-th-unbox
库会将您的数据类型与N个字段转换为N元组,然后使用Unbox
库提供的vector
实例N元组。 7元组失败的原因是vector
库只提供最多6元组的实例。
修复方法是:
(A)更新vector-th-unbox
库以不使用元组中间变通方法来派生Unbox
个实例,而只是直接派生Unbox
实例或:
(B)将更大元组的Unbox
个实例添加到vector
库
从长远来看,解决方案(A)是更好的解决方案。