[Haskell-cafe] Newbie question about tuples

Jonathan Cast jcast at ou.edu
Thu Jul 12 15:59:53 EDT 2007


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?

If you have instances of Data across the board, you should be able to do this 
with gmap, gfoldl, etc.  (See Data.Generics).  Short of that, you'd have a 
hard time writing the type of liftN.

> 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?

Use Data.Dynamic.Dynamic instead of explicit existentially quantified types, 
and it should come from gfoldl pretty readily.

<snip>

Jonathan Cast
http://sourceforge.net/projects/fid-core
http://sourceforge.net/projects/fid-emacs


More information about the Haskell-Cafe mailing list