I'm rather new to Haskell and was looking at this post here: Cartesian product of 2 lists in Haskell.
In the answer there is this snippet of code:
cartProd xs ys = [(x,y) | x <- xs, y <- ys]
Which with these two lists:
xs = [1,2,3]
ys = [4,5,6]
would yield
[(1,4),(1,5),(1,6),(2,4),(2,5),(2,6),(3,4),(3,5),(3,6)]
Had I not seen this result I would have assumed it would just have returned
[(1,4),(2,5),(3,6)]
because it would traverse both lists at the same time.
But now it - to programming languages I know better - looks like a double for loop used to traverse a matrix:
for (int x = 1; x < 4; x++)
for(int y = 4; y < 7; y++)
//make tuple (x,y)
What causes a list comprehension to behave in this manner?