[Haskell-cafe] Tupling functions

Richard O'Keefe ok at cs.otago.ac.nz
Wed Sep 14 03:56:11 CEST 2011

On 14/09/2011, at 1:44 PM, Chris Smith wrote:

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

> There is no polymorphism across tuple structures,

I know that.  I know how tuples get to be instances of Ix,
one instance declaration for each of (,) (,,) (,,,) ....

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

I don't *expect* to implement anything just once.  I am perfectly
happy writing as many instance declarations as I have tuple sizes
that I care about.  It's just that I can't see how to get the types
right, because in

    class Thingy t ... where
	tuple :: t -> a -> b

b depends on t and possibly a, so

    instance Thingy (,,) where
	tuple (f,g,h) x = (f x, g x, h x)

it's not an arbitrary b.  Can this be done with functional dependencies?

More information about the Haskell-Cafe mailing list