Re: [Haskell-cafe] zip3, zip4 ... -> zipn?
On Sat, Aug 11, 2007 at 09:58:05AM +0200, Frank Buss wrote: > Is it possible to write a function like this: > > zipn n list_1 list_2 list_3 ... list_n > > which implements zip3 for n=3, zip4 for n=4 etc.? Looks like variable number > of arguments are possible, like printf shows, so a general zipn should be > possible, too. If it is possible, why there are functions like zip5 and not > just zipn? I prefer to do n-ary zips this way: zipApply = zipWith ($) x = repeat (,,) `zipApply` [1,2,3] `zipApply` ["a", "bc", "de"] `zipApply` [1.0, 1.2..] Best regards Tomek ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] zip3, zip4 ... -> zipn?
On Sun, Aug 12, 2007 at 12:56:31PM +1000, Alexis Hazell wrote: > On Sunday 12 August 2007 05:24, Stefan O'Rear wrote: > > > Currying makes it MUCH harder to implement varargs functions. > > That's interesting - why is that the case? varsum 2 3 -- varsum receives 2, and returns a function, which when -- passed 3, returns 5 varsum 2 3 4 -- varsum receives 2, and returns a function, which when -- passed 3, returns a function that when passed 4 returns -- 9. Because of this, the number of arguments must somehow be passed out-of-band; but then the type of the whole function (usually) must depend on the control parameter, requiring dependent types. Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] zip3, zip4 ... -> zipn?
On Sunday 12 August 2007 05:24, Stefan O'Rear wrote: > Currying makes it MUCH harder to implement varargs functions. That's interesting - why is that the case? Alexis. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] zip3, zip4 ... -> zipn?
On Sat, Aug 11, 2007 at 05:27:19PM +0800, Hugh Perkins wrote: > I was looking for something like this too. > > Note that Erlang can do this ;-) but Erlang is probably not so > strongly typed, so it's easier to do? I think the main issue is that Erlang doesn't use currying (IIRC). Currying makes it MUCH harder to implement varargs functions. (We thought this was a good tradeoff - partial applications give Haskell much more power than varargs would have.) (Unfortunately I don't know of any good languages with powerful type systems and vararg functions that can take advantage of powerful types... I'd love to give example code here :)) Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] zip3, zip4 ... -> zipn?
On 8/11/07, Frank Buss <[EMAIL PROTECTED]> wrote: > > Is it possible to write a function like this: > > zipn n list_1 list_2 list_3 ... list_n > > which implements zip3 for n=3, zip4 for n=4 etc.? Looks like variable > number > of arguments are possible, like printf shows, so a general zipn should be > possible, too. If it is possible, why there are functions like zip5 and > not > just zipn? Template Haskell can also be used to generate appropriate code for zipn (in fact, the original paper on TH even uses this as an example [1]). But again, this approach only works if the value of n is known at compile time. -Brent [1] http://www.haskell.org/th/papers/meta-haskell.ps ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] zip3, zip4 ... -> zipn?
I was looking for something like this too. Note that Erlang can do this ;-) but Erlang is probably not so strongly typed, so it's easier to do? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] zip3, zip4 ... -> zipn?
Frank, The return type of zipn would have to depend on the number of arguments. If you are satisfied with all arguments having the same type, then you can use transpose: zipn list1 list2 .. listn => transpose [list1, list2, .. listn] Can we make a polyvariadic zipn that returns a [HList]? Seems like a neat challenge, but I'm a bit pressed for time right now. I'm afraid it would be pretty unwieldy. I'm looking forward to seeing solutions though. :-) -- Joel ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] zip3, zip4 ... -> zipn?
Is it possible to write a function like this: zipn n list_1 list_2 list_3 ... list_n which implements zip3 for n=3, zip4 for n=4 etc.? Looks like variable number of arguments are possible, like printf shows, so a general zipn should be possible, too. If it is possible, why there are functions like zip5 and not just zipn? -- Frank Buss, [EMAIL PROTECTED] http://www.frank-buss.de, http://www.it4-systems.de ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe