This program:
{-# 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
Fails to compile, with this error message:
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))
How can I fix this problem?
I believe this is because under the hood the vector-th-unbox
library converts your data type with N fields into an N-tuple and then uses the Unbox
instance provided by the vector
library for N-tuples. The reason this fails for 7-tuples is that the vector
library only provides instances up to 6-tuples.
The fix is to either:
(A) Update the vector-th-unbox
library to not use the tuple intermediate workaround to derive Unbox
instances and instead just derive the Unbox
instance directly or:
(B) Add Unbox
instances for larger tuples to the vector
library
Solution (A) is the better solution in the long run.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With