[Haskell-cafe] Permutations
Miguel Mitrofanov
miguelimo38 at yandex.ru
Sun Nov 30 12:02:09 EST 2008
First line is necessary, because the second line is written in
assumption that the first element of a permutation does really exist.
On 30 Nov 2008, at 19:49, Andrew Coppin wrote:
> 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.
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
More information about the Haskell-Cafe
mailing list