[Haskell-cafe] Newbie question about tuples
bf3 at telenet.be
Thu Jul 12 03:51:56 EDT 2007
I have a couple of questions about tuples.
Q1) Is it possible to treat a tuple of N elements in a generic way? So
instead of writing functions like lift1 e1, lift2 (e1,e2), lift3 (e1,e2,e3)
just one function liftN that works on tuples of any length?
Q2) (Maybe related to Q1) Can I convert a tuple of length N to a
heterogeneous list (using "forall" aka existentially quantified types) and
Q3) Suppose I want to declare an instance of Num on all tuple types having
(Num instances) as elements; is this possible?
instance Num a => Num (a,a) where .
but this fails
I also tried
instance Num a => Num ((,) a a) where .
but that also fails.
I can of course create a new type like
newtype Num a => Vector2 a = Vector2 (a,a)
and then create an instance for Vector2, but I was wondering if it would be
possible without introducing a new type.
More information about the Haskell-Cafe