Possible Duplicate:
Cartesian product
I'm Haskell newbie and I have a problem. I want to do some function that will take first element of list and connect to all elements of second list, after that take second element from first list and do the same. For example I want to take: [[1],[2],[3]) and [[4],[5],[6]] and get in output
[([1],[4]),([1],[5]),([1],[6]),
([2],[4]),([2],[5]),([2],[6]),
([3],[4]),([3],[5]),([3],[6])]
The closes one I found is transpose
transpose [[1,2,3],[4,5,6]]
[[1,4],[2,5],[3,6]]
I would appreciate any help.
Edit: Shame on me. I found solution
[[x,y] | x <- [[1],[2],[3]], y <- [[4],[5],[6]]]
Which result is:
[[[1],[4]],[[1],[5]],[[1],[6]],[[2],[4]],[[2],[5]],[[2],[6]],[[3],[4]],[[3],[5]],[[3],[6]]]