[Haskell-cafe] Tupling functions

Chris Smith cdsmith at gmail.com
Wed Sep 14 04:03:48 CEST 2011


On Wed, 2011-09-14 at 13:56 +1200, Richard O'Keefe wrote:
> 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.

Ah, okay... then sure, you can do this:

class Tuple a b c | a b -> c where
    tuple :: a -> b -> c

instance Tuple (a -> b, a -> c) a (b,c) where
    tuple (f,g) x = (f x, g x)

and so on...  You'll need fundeps (or type families if you prefer to
write it that way), and probably at least flexible and/or overlapping
instances, too, but of course GHC will tell you about those.

-- 
Chris Smith




More information about the Haskell-Cafe mailing list