[Haskell-cafe] in the vector library, why define unbox tuples > 2?

Jeff Shaw shawjef3 at gmail.com
Tue Sep 25 16:58:19 CEST 2012

I'm looking at storing a data type with 7 fields in an unboxed vector, 
which means that I'll have to use GenUnboxTuple to create an instance 
for Unbox (a,b,c,d,e,f,g), but I was thinking that another solution is 
to use "instance (Unbox a, Unbox b) => Unbox (a,b)" recursively to 
create "instance Unbox (a,(b,(c,(d,(e,(f,g))))))". Is there any reason I 
shouldn't say something like,

import qualified Data.Vector.Unboxed as Vector

data X = X Int Int Int Int Int Int Int

toTuple (X a b c d e f g) = (a,(b,(c,(d,(e,(f,g))))))

toVector = Vector.fromList . map toTuple

I guess I'm wondering if there is a technical reason why I should use an 
explicit Unbox instance for 7-tuples, or if it's just a convenience to 
have Unbox defined for tuples > 2?


More information about the Haskell-Cafe mailing list