Re: [Haskell-cafe] Tupling functions

2011-09-15 Thread Casey McCann
On Thu, Sep 15, 2011 at 7:51 AM, Markus Läll wrote: > Intuitively it seems to be exactly the same as the type families' > aproach, and looks quite clear too. Not exact, no--as written, it's strictly more powerful. Your fundeps go in both directions, whereas the type families didn't (though could

Re: [Haskell-cafe] Tupling functions

2011-09-15 Thread Markus Läll
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

Re: [Haskell-cafe] Tupling functions

2011-09-14 Thread Richard O'Keefe
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

Re: [Haskell-cafe] Tupling functions

2011-09-14 Thread Casey McCann
On Wed, Sep 14, 2011 at 9:32 AM, Victor Nazarov wrote: > I've just tried another approach (code below). And GHC even inferred > type for tupleF. But I think GHC inferred the wrong type and I can't > formulate the right one, it seems to require infinite number of > constraints. With GHC inferred ty

Re: [Haskell-cafe] Tupling functions

2011-09-14 Thread Victor Nazarov
On Wed, Sep 14, 2011 at 6:45 AM, Casey McCann wrote: > On Tue, Sep 13, 2011 at 10:03 PM, Chris Smith wrote: >> 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

Re: [Haskell-cafe] Tupling functions

2011-09-13 Thread Casey McCann
On Tue, Sep 13, 2011 at 10:03 PM, Chris Smith wrote: > 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) This wouldn't actually work well in practice. There's n

Re: [Haskell-cafe] Tupling functions

2011-09-13 Thread Chris Smith
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 tup

Re: [Haskell-cafe] Tupling functions

2011-09-13 Thread Richard O'Keefe
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.

Re: [Haskell-cafe] Tupling functions

2011-09-13 Thread Chris Smith
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 &&& combin

[Haskell-cafe] Tupling functions

2011-09-13 Thread Richard O'Keefe
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 hav