[Haskell-cafe] Tupling functions

Chris Smith cdsmith at gmail.com
Wed Sep 14 03:44:20 CEST 2011


On Wed, 2011-09-14 at 13:35 +1200, Richard O'Keefe wrote:
> I would like to have
> 
> 	tuple (f1,f2)       x = (f1 x, f2 x)
> 	tuple (f1,f2,f3)    x = (f1 x, f2 x, f3 x)
> 	tuple (f1,f2,f3,f4) x = (f1 x, f2 x, f3 x, f4 x)
> 	...
> 
> I'm aware of Control.Arrow and the &&& combinator, and I can use that
> instead, but f1 &&& f2 &&& f3 doesn't have _exactly_ the type I want.
> 
> What should I do?

There is no polymorphism across tuple structures, so if you absolutely
*must* have n-tuples instead of nested 2-tuples, then you just need to
implement the new functions as needed.  You can't implement that only
once.  Plenty of places in base do this, especially for instances.

-- 
Chris Smith





More information about the Haskell-Cafe mailing list