So lets say I want a function foo, that takes as argument, any number of lists, and return every combinations of the lists elements.
So for instance, foo [0,1] [0,1,2]
would return [[0,0],[0,1],[0,2],[1,0],[1,1],[1,2]]
and foo [0,1] [0,1] [0,1]
would return [[0,0,0],[0,0,1],[0,1,0],[1,0,0],[1,1,0],[1,0,1]]
I was thinking of working recursively, and for the second example for instance, having foo x y = [[a,b]|a <- x, b <- y]
, and essentially call foo (foo [1,0] [1,0]) [0,1]
But the problem i have right now is that foo returns a list of a list, so the more arguments i give it, the more nested lists it will have and the recursive calls won't work. Does anyone have any idea on how i can approach such a function?
I think working with foo x y is a good idea, so that i can recursively call it on any number of lists. So if i had ls = [[0,1],[0,1],[0,1,2],[0,1,2,3],[0,1,2,3,4]] I would call foo on the first two and then on the next one and so on.