If I wanted to find the permutations of a list, I know that the number of permutations is given by the multinomial coefficient. For example, "MISSISSIPPI" has 11 letters, 'S' appears 4 times, 'I' appears 4 times, 'P' appears twice and 'M' appears once. So the number of permutations of "MISSISSIPPI" is equal to 11!/(4!4!2!) = 34650.
If I load up GHCi and write:
ghci> import Data.List
ghci> permutations [1,2,3]
It will return
[[1,2,3],[2,1,3],[3,2,1],[2,3,1],[3,1,2],[1,3,2]]
as expected.
But if I write
ghci> permutations [1,0,0]
it will now return
[[1,0,0],[0,1,0],[0,0,1],[0,0,1],[0,1,0],[1,0,0]]
... which is very disappointing. As there are three elements, and two of them occur twice, one would hope for there only to be 6!/2! = 3 permutations, namely
[[1,0,0],[0,1,0],[0,0,1]]
rather than the six generated by treating each element of the list as distinct.
1) Why does Haskell implement "permutations" in the way described above (i.e. treating all elements of a list as distinct?)
2) Are there any standard library functions that calculate the permutations of a list in the "true" sense of permutations?