[Haskell-cafe] Tupling functions

Markus Läll markus.l2ll at gmail.com
Thu Sep 15 13:51:48 CEST 2011


Using fundeps I came up with this:

class T funs arg res | funs -> arg res, arg res -> funs where
   tuple :: funs -> arg -> res

instance (a ~ a0, a0 ~ a1) => T (a0 -> b, a1 -> c) a (b, c) where
   tuple (f, g) a = (f a, g a)

instance (a ~ a0, a0 ~ a1, a1 ~ a2) => T (a0 -> b, a1 -> c, a2 -> d) a
(b, c, d) where
   tuple (f, g, h) a = (f a, g a, h a)


Intuitively it seems to be exactly the same as the type families'
aproach, and looks quite clear too.


On 9/15/11, Richard O'Keefe <ok at cs.otago.ac.nz> wrote:
>
> On 14/09/2011, at 2:45 PM, Casey McCann wrote:
>
>>
>>    class Tuple t where
>>        type Arg t :: *
>>        type Result t :: *
>>        tuple :: t -> Arg t -> Result t
>>
>>    instance (x1 ~ x2) => Tuple (x1 -> a, x2 -> b) where
>>        type Arg (x1 -> a, x2 -> b) = x1
>>        type Result (x1 -> a, x2 -> b) = (a, b)
>>        tuple (f, g) x = (f x, g x)
>
> That's it, that's what I was after.  Thanks.
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>


-- 
Markus Läll



More information about the Haskell-Cafe mailing list