I have a list:
let a = [1, 2, 3]
I need to get another list:
[1, 2, 3] ++ [1*2, 2*3, 1*3] ++ [1*2*3]
It is a product of all possible unique coombinations of list’s elements. I have founded permutations in Data.List, but as I see it is something different.
Is there any library functions to get this list or can you give me examles how can I create your own function.
Thanks.
For a library function, you can use
subsequencesfromData.List:You can get all of the products using
map product $ subsequences [1,2,3].But that is not in the same order as you specified. So you can sort it,
using
sortByfromData.ListandcomparingfromData.Ord:Again, get the products using
map product.Your other idea, to write a function yourself, is
the best idea if you are learning Haskell. Give it a try!