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

apfelmus apfelmus at quantentunnel.de
Mon Nov 24 11:37:40 EST 2008

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 function will not involve tuples, since they can be
> arbitrary length (dynamic-length tuples are not supported in Haskell;
> we use lists for that).
> cross :: [[a]] -> [[a]]
> ....

This is the  sequence  function from Control.Monad.

  cross :: [[a]] -> [[a]]
  cross = sequence

  > cross [[1,2],[3,4]]


More information about the Haskell-Cafe mailing list