Benjamin.Rudiak-Gould at cl.cam.ac.uk
Wed Feb 8 16:49:30 EST 2006
Robert Dockins wrote:
> data Tuple a b = Tuple a !b
> -- (a,b) === Tuple a (Tuple b ())-- (a,b,c) === Tuple a (Tuple b
> (Tuple c ()))
> -- etc...
A problem with this is that there's no way of supporting partially-applied
tuple type constructors without some sort of type system extension. But
maybe there's no reason to support this. Are there any situations where
people use "(,) a" where they couldn't simply define a new product type?
I rather like the following solution for traversable tuples:
Introduce unboxed pairs (# a,b #) and unboxed unit (# #) into the language.
Allow datatypes to be specialized at unboxed types. Define
data Tuple a = Tuple a
(a,b) = Tuple (# a,(# b,(# #)#)#)
(a,b,c) = Tuple (# a,(# b,(# c,(# #)#)#)#)
Then allow class instances to be declared at unboxed types and type
parameters to be instantiated at unboxed types by doing compile-time
specialization (like C++ templates), and voila. No problem of ordinary tuple
access becoming less efficient, though some care would be needed to prevent
typeclass-based traversal from taking O(n^2) time.
Of course, the compile-time specialization part is a bit tricky.
More information about the Haskell-prime