[Haskell-cafe] Re: Generic permutations

Cetin Sert cetin.sert at gmail.com
Sat Jan 26 18:20:06 EST 2008


Thanks Jed,

replicateM is almost as performant as pms on my pc (+ 2~ seconds).

That's a killer suggestion... thank you very much ^_^

--Cetin Sert

On 27/01/2008, Jed Brown <jed at 59a2.org> 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
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080127/b0441252/attachment.htm


More information about the Haskell-Cafe mailing list