Cartesian product over a list of lists in Haskell
问题 Given a list of lists of length x where all the sublists have the same length y , output the y^x lists of length x that contain one item from each sublist. Example ( x = 3 , y = 2 ): [ [1, 2], [3, 4], [5, 6] ] Output ( 2^3 == 8 different outputs): [ [1, 3, 5], [1, 4, 5], [1, 3, 6], [1, 4, 6], [2, 3, 5], [2, 4, 5], [2, 3, 6], [2, 4, 6] ] My research / Work Ruby I wrote actual code to perform this task, but in Ruby, as it is the language I am most comfortable with. def all_combinations(lst) lst