[Haskell-cafe] Re: howto tuple fold to do n-ary cross product?

2008-12-01 Thread Larry Evans
On 11/30/08 12:49, Larry Evans wrote: [snip] You'll see Domains can be an mpl::vector of any length. The cross_nproduct_view_test.cpp tests with a 3 element Domains: typedef mpl::vector mpl::range_cint,0,4 , mpl::range_cint,100,103 , mpl::range_cint,2000,2002

[Haskell-cafe] Re: howto tuple fold to do n-ary cross product?

2008-11-30 Thread Larry Evans
On 11/23/08 13:52, Luke Palmer wrote: 2008/11/23 Larry Evans [EMAIL PROTECTED]: http://www.muitovar.com/monad/moncow.xhtml#list contains a cross function which calculates the cross product of two lists. That attached does the same but then used cross on 3 lists. Naturally, I thought use of

Re: [Haskell-cafe] Re: howto tuple fold to do n-ary cross product?

2008-11-30 Thread Luke Palmer
On Sun, Nov 30, 2008 at 10:25 AM, Larry Evans [EMAIL PROTECTED] wrote: Is there some version of haskell, maybe template haskell, that can do that, i.e. instead of: cross::[[a]] - [[a]] have: crossn::[a0]-[a1]-...-[an] - [(a0,a1,...,an)] Ah yes! This is straightforward usage of the list

Re: [Haskell-cafe] Re: howto tuple fold to do n-ary cross product?

2008-11-30 Thread Max Rabkin
On Sun, Nov 30, 2008 at 9:30 AM, Luke Palmer [EMAIL PROTECTED] wrote: cross :: [a] - [b] - [(a,b)] It's just kind of a pain (you build [(a,(b,(c,d)))] and then flatten out the tuples). The applicative notation is a neat little trick which does this work for you. It seems to me like this

Re: [Haskell-cafe] Re: howto tuple fold to do n-ary cross product?

2008-11-30 Thread Brandon S. Allbery KF8NH
On 2008 Nov 30, at 12:43, Max Rabkin wrote: On Sun, Nov 30, 2008 at 9:30 AM, Luke Palmer [EMAIL PROTECTED] wrote: cross :: [a] - [b] - [(a,b)] It's just kind of a pain (you build [(a,(b,(c,d)))] and then flatten out the tuples). The applicative notation is a neat little trick which does

Re: [Haskell-cafe] Re: howto tuple fold to do n-ary cross product?

2008-11-30 Thread Ganesh Sittampalam
On Sun, 30 Nov 2008, Brandon S. Allbery KF8NH wrote: On 2008 Nov 30, at 12:43, Max Rabkin wrote: It seems to me like this would all be easy if (a,b,c,d) was sugar for (a,(b,(c,d))), and I can't see a disadvantage to that. No disadvantage aside from it making tuples indistinguishable from

[Haskell-cafe] Re: howto tuple fold to do n-ary cross product?

2008-11-30 Thread Larry Evans
On 11/30/08 11:30, Luke Palmer wrote: On Sun, Nov 30, 2008 at 10:25 AM, Larry Evans [EMAIL PROTECTED] wrote: Is there some version of haskell, maybe template haskell, that can do that, i.e. instead of: cross::[[a]] - [[a]] have: crossn::[a0]-[a1]-...-[an] - [(a0,a1,...,an)] Ah yes! This

Re: [Haskell-cafe] Re: howto tuple fold to do n-ary cross product?

2008-11-30 Thread Luke Palmer
On Sun, Nov 30, 2008 at 10:43 AM, Max Rabkin [EMAIL PROTECTED] wrote: On Sun, Nov 30, 2008 at 9:30 AM, Luke Palmer [EMAIL PROTECTED] wrote: cross :: [a] - [b] - [(a,b)] It's just kind of a pain (you build [(a,(b,(c,d)))] and then flatten out the tuples). The applicative notation is a neat

Re: [Haskell-cafe] Re: howto tuple fold to do n-ary cross product?

2008-11-30 Thread Miguel Mitrofanov
Tuples would still be distinguishable from lists, since cons changes their type: (b,c,d) and (a,b,c,d) would have different types, while [b,c,d] and [a,b,c,d] wouldn't. On 30 Nov 2008, at 20:48, Brandon S. Allbery KF8NH wrote: On 2008 Nov 30, at 12:43, Max Rabkin wrote: On Sun, Nov 30,

[Haskell-cafe] Re: howto tuple fold to do n-ary cross product?

2008-11-30 Thread Larry Evans
On 11/30/08 12:04, Larry Evans wrote: [snip] The following post: http://thread.gmane.org/gmane.comp.lib.boost.devel/182797 shows at least one person that would find it useful, at least in c++. Of course maybe it would be less useful in haskell. One thing that maybe confusing things is

Re: [Haskell-cafe] Re: howto tuple fold to do n-ary cross product?

2008-11-30 Thread Luke Palmer
On Sun, Nov 30, 2008 at 11:04 AM, Larry Evans [EMAIL PROTECTED] wrote: The following post: http://thread.gmane.org/gmane.comp.lib.boost.devel/182797 shows at least one person that would find it useful, at least in c++. Of course maybe it would be less useful in haskell. The line:

Re: [Haskell-cafe] Re: howto tuple fold to do n-ary cross product?

2008-11-30 Thread Daniel Fischer
Am Sonntag, 30. November 2008 19:04 schrieb Larry Evans: If you're asking whether crossn, as a single function which handles arbitrarily many arguments, can be defined, the short answer is no. I dare you to come up with a case in which such function adds more than cursory convenience.

[Haskell-cafe] Re: howto tuple fold to do n-ary cross product?

2008-11-30 Thread Larry Evans
On 11/30/08 12:27, Luke Palmer wrote: On Sun, Nov 30, 2008 at 11:04 AM, Larry Evans [EMAIL PROTECTED] wrote: The following post: http://thread.gmane.org/gmane.comp.lib.boost.devel/182797 shows at least one person that would find it useful, at least in c++. Of course maybe it would be less

Re: [Haskell-cafe] Re: howto tuple fold to do n-ary cross product?

2008-11-30 Thread Martijn van Steenbergen
Larry Evans wrote: The haskell code: cross::[[a]]-[[a]] calculate a cross product of values. Now if you allow the elements of that function's argument list to be possibly infinite lists and you still want to eventually yield every possible cross product, you get a very nice problem...

Re: [Haskell-cafe] Re: howto tuple fold to do n-ary cross product?

2008-11-30 Thread Luke Palmer
On Sun, Nov 30, 2008 at 2:07 PM, Martijn van Steenbergen [EMAIL PROTECTED] wrote: Larry Evans wrote: The haskell code: cross::[[a]]-[[a]] calculate a cross product of values. Now if you allow the elements of that function's argument list to be possibly infinite lists and you still want

Re: [Haskell-cafe] Re: howto tuple fold to do n-ary cross product?

2008-11-30 Thread Lennart Augustsson
You can have seq and lifted tuples, but the implementation of seq requires parallel evaluation. -- Lennart On Sun, Nov 30, 2008 at 7:00 PM, Luke Palmer [EMAIL PROTECTED] wrote: On Sun, Nov 30, 2008 at 10:43 AM, Max Rabkin [EMAIL PROTECTED] wrote: On Sun, Nov 30, 2008 at 9:30 AM, Luke Palmer

Re: [Haskell-cafe] Re: howto tuple fold to do n-ary cross product?

2008-11-30 Thread Martijn van Steenbergen
Luke Palmer wrote: The other nice one problem is allowing the argument itself to be infinite (you have to require all of the lists to be nonempty). I think the requirement has to be a lot stronger for that to work. If every sublist has two elements, the answer is 2^infinity lists which is

Re: [Haskell-cafe] Re: howto tuple fold to do n-ary cross product?

2008-11-30 Thread Luke Palmer
On Sun, Nov 30, 2008 at 3:13 PM, Martijn van Steenbergen [EMAIL PROTECTED] wrote: Luke Palmer wrote: The other nice one problem is allowing the argument itself to be infinite (you have to require all of the lists to be nonempty). I think the requirement has to be a lot stronger for that to

[Haskell-cafe] Re: howto tuple fold to do n-ary cross product?

2008-11-24 Thread Larry Evans
On 11/24/08 00:40, Andrea Vezzosi wrote: It's more natural to consider the cross product of no sets to be [[]] so your crossr becomes: crossr [] = [[]] crossr (x:xs) = concat (map (\h -map (\t - h:t) (crossr tail)) hd) which we can rewrite with list comprehensions for conciseness: crossr []

[Haskell-cafe] Re: howto tuple fold to do n-ary cross product?

2008-11-24 Thread apfelmus
Luke Palmer wrote: Larry Evans wrote: contains a cross function which calculates the cross product of two lists. That attached does the same but then used cross on 3 lists. Naturally, I thought use of fold could generalize that to n lists; however, I'm getting error: The type of the

[Haskell-cafe] Re: howto tuple fold to do n-ary cross product?

2008-11-23 Thread Larry Evans
On 11/23/08 13:52, Luke Palmer wrote: 2008/11/23 Larry Evans [EMAIL PROTECTED]: http://www.muitovar.com/monad/moncow.xhtml#list contains a cross function which calculates the cross product of two lists. That attached does the same but then used cross on 3 lists. Naturally, I thought use of

Re: [Haskell-cafe] Re: howto tuple fold to do n-ary cross product?

2008-11-23 Thread Andrea Vezzosi
It's more natural to consider the cross product of no sets to be [[]] so your crossr becomes: crossr [] = [[]] crossr (x:xs) = concat (map (\h -map (\t - h:t) (crossr tail)) hd) which we can rewrite with list comprehensions for conciseness: crossr [] = [[]] crossr (x:xs) = [ a:as | a - x, as

Re: [Haskell-cafe] Re: howto tuple fold to do n-ary cross product?

2008-11-23 Thread Andrea Vezzosi
On Mon, Nov 24, 2008 at 7:40 AM, Andrea Vezzosi [EMAIL PROTECTED] wrote: It's more natural to consider the cross product of no sets to be [[]] so your crossr becomes: crossr [] = [[]] crossr (x:xs) = concat (map (\h -map (\t - h:t) (crossr tail)) hd Ops, hd and tail should be x and xs