[Haskell-cafe] How to do the "permutation and combination" thing?

Richard O'Keefe ok at cs.otago.ac.nz
Sun Mar 14 16:38:45 EDT 2010


The first question is "what does 'all the combinations' actually MEAN?"

We are told that

	f [a,b,c] [d,e,f] [g,h,i] =
	  [[(a,d,g),(b,e,h),(c,f,i)], ...]

in which the first element of the result is just
zip3 [a,b,c] [d,e,f], [g,h,i].  But what are the
other elements?  Why is "all the combinations" a list
of lists of tuples rather than a list of tuples?

At first I thought you were after
	f xs ys zs = [(x,y,z) | x <- xs, y <- ys, z <- zs]
because that's what I would mean by "all the combinations",
but the example shows that's not so.

When you can explain clearly what you mean by "all the
combinations", the code won't be far away.




More information about the Haskell-Cafe mailing list