Cartesian product of 2 lists in Haskell
问题 I wish to produce the Cartesian product of 2 lists in Haskell, but I cannot work out how to do it. The cartesian product gives all combinations of the list elements: xs = [1,2,3] ys = [4,5,6] cartProd :: [a] -> [b] -> [(a,b)] cartProd xs ys ==> [(1,4),(1,5),(1,6),(2,4),(2,5),(2,6),(3,4),(3,5),(3,6)] This is not an actual homework question and is not related to any such question, but the way in which this problem is solved may help with one I am stuck on. 回答1: This is very easy with list