[Haskell-cafe] Permutations

Andrew Coppin andrewcoppin at btinternet.com
Sun Nov 30 11:49:28 EST 2008


Miguel Mitrofanov wrote:
> eqPerms [] = [[]]
> eqPerms xs = [x:xt | x <- nub xs, xt <- eqPerms $ delete x xs]

Well, that's one way... ;-)

I'm still not precisely sure why the first line must exist, but it seems 
no matter which way round you do it, that line is needed. Probably due 
to some subtlety of the list monad...

I'm not sure how efficient using the delete function is, but this 
version definitely has the virtues of brevity and readbility.



More information about the Haskell-Cafe mailing list