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

Larry Evans cppljevans at suddenlink.net
Sun Nov 23 14:24:18 EST 2008


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
fold could generalize that to n lists; however,
I'm getting error:

{-- cut here
Compilation started at Sun Nov 23 13:15:24

make
runghc -XMultiParamTypeClasses -XFunctionalDependencies 
-XFlexibleInstances cross.hs

cross.hs:23:30:
     Occurs check: cannot construct the infinite type: a = (a, a)
       Expected type: [a] -> [a] -> [a]
       Inferred type: [a] -> [a] -> [(a, a)]
     In the first argument of `Data.Foldable.foldl1', namely `cross'
     In the first argument of `print', namely
         `(Data.Foldable.foldl1 cross (list2, list3, list1))'
make: *** [run] Error 1

}-- cut here

How do I apply fold to cross and n lists, for n>=0?

TIA.

-regards,
Larry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cross.hs
Type: text/x-haskell
Size: 479 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20081123/49e09d22/cross.bin


More information about the Haskell-Cafe mailing list