[Haskell-cafe] Newbie question about tuples
Benja Fallenstein
benja.fallenstein at gmail.com
Thu Jul 12 04:03:24 EDT 2007
Hi Peter,
2007/7/12, peterv <bf3 at telenet.be>:
> 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
> vice versa?
Not in the standard libraries.
I've been using a home-grown module for this sort of thing:
http://antti-juhani.kaijanaho.fi/darcs/fenserve/fendata/TupleUtils.hs
> 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
This is illegal in Haskell 98, but should work in GHC if you use -fglasgow-exts.
- Benja
More information about the Haskell-Cafe
mailing list