If I wanted to find permutations in the list, I know that the number of permutations is specified using the polynomial. For example, “MISSISSIPPI” has 11 letters, “S” appears 4 times, “I” appears 4 times, “P” appears twice, and “M” appears once. Therefore, the number of permutations of "MISSISSIPPI" is 11! / (4! 4! 2!) = 34650.
If I download GHCi and write:
ghci> import Data.List ghci> permutations [1,2,3]
He will return
[[1,2,3],[2,1,3],[3,2,1],[2,3,1],[3,1,2],[1,3,2]]
as was expected.
But if I write
ghci> permutations [1,0,0]
now he will return
[[1,0,0],[0,1,0],[0,0,1],[0,0,1],[0,1,0],[1,0,0]]
... which is very disappointing. Since there are three elements, and two of them occur twice, it is hoped that there will only be 6! / 2! = 3, namely
[[1,0,0],[0,1,0],[0,0,1]]
not six created by treating each list item as a separate one.
1) Why does Haskell implement “permutations” in the manner described above (that is, treating all elements of the list as different?)
2) Are there any standard library functions that compute list permutations in the "true" sense of permutations?