[Haskell-cafe] Re: Generic permutations

Jed Brown jed at 59A2.org
Sat Jan 26 18:03:07 EST 2008


On 26 Jan 2008, ryani.spam at gmail.com wrote:

> The problem you solved can be solved much more elegantly:
>
> pms : [a] -> Int -> [[a]]
> pms xs n = foldM combine [] (replicate n xs) where
> combine rest as = liftM (:rest) as
>
> or, for the unreadable version:
> pms xs n = foldM (map . flip (:)) [] $ replicate n xs

or, if you don't mind getting the elements in a different order:

  replicateM 3 [True,False]

Jed
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20080127/662e593b/attachment.bin


More information about the Haskell-Cafe mailing list