
peterv wrote:
Hi,
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?
The only thing the libraries provide, as far as I can tell, is the fact that tuples are all Functors. (In other words, you can apply some function to all the elements to get a new tuple.) I think that's about it. I doubt you can use that to define lifting functions...
Q2) (Maybe related to Q1) Can I convert a tuple of length N to a heterogeneous list (using "forall" aka existentially quantified types) and vice versa?
I think you're going to need to play with type classes to do that.
Q3) Suppose I want to declare an instance of Num on all tuple types having (Num instances) as elements; is this possible?
I tried
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 tried to do this a while ago and couldn't figure out how. :-(