Re: Data.List permutations

2009-08-05 Thread Yitzchak Gale
Hi Slavomir, Slavomir Kaslev wrote: inter x [] = [[x]] inter x yys@(y:ys) = [x:yys] ++ map (y:) (inter x ys) perm [] = [[]] perm (x:xs) = concatMap (inter x) (perm xs) I was surprised to find that not only my version is much simpler from the one in Data.List but it also performs better.

Re: Data.List permutations

2009-08-05 Thread Slavomir Kaslev
Thank you for the comprehensive reply Yitzchak. On Wed, Aug 5, 2009 at 2:22 PM, Yitzchak Galeg...@sefer.org wrote: Hi Slavomir, Slavomir Kaslev wrote: inter x [] = [[x]] inter x yys@(y:ys) = [x:yys] ++ map (y:) (inter x ys) perm [] = [[]] perm (x:xs) = concatMap (inter x) (perm xs) I

Re: Data.List permutations

2009-08-04 Thread Krasimir Angelov
Your function is not equivalent: perm _|_ = _|_ permutations _|_ = _|_ : _|_ On 8/4/09, Slavomir Kaslev slavomir.kas...@gmail.com wrote: A friend mine, new to functional programming, was entertaining himself by writing different combinatorial algorithms in Haskell. He asked me for some help

Re: Data.List permutations

2009-08-04 Thread Slavomir Kaslev
On Tue, Aug 4, 2009 at 8:53 PM, Krasimir Angelovkr.ange...@gmail.com wrote: Your function is not equivalent: perm _|_ = _|_ permutations _|_ = _|_ : _|_ Nice catch. One can use the same trick as in permutations: perm2 [] = [[]] perm2 xxs@(x:xs) = xxs : tail (concatMap (inter x) (perm2

Re: Data.List permutations

2009-08-04 Thread Daniel Fischer
Am Dienstag 04 August 2009 19:48:25 schrieb Slavomir Kaslev: A friend mine, new to functional programming, was entertaining himself by writing different combinatorial algorithms in Haskell. He asked me for some help so I sent him my quick and dirty solutions for generating variations and

Re: Data.List permutations

2009-08-04 Thread Slavomir Kaslev
On Tue, Aug 4, 2009 at 9:23 PM, Daniel Fischerdaniel.is.fisc...@web.de wrote: Am Dienstag 04 August 2009 19:48:25 schrieb Slavomir Kaslev: A friend mine, new to functional programming, was entertaining himself by writing different combinatorial algorithms in Haskell. He asked me for some help

Re: Data.List permutations

2009-08-04 Thread Daniel Fischer
Am Dienstag 04 August 2009 20:30:58 schrieb Slavomir Kaslev: On Tue, Aug 4, 2009 at 9:23 PM, Daniel Fischerdaniel.is.fisc...@web.de wrote: Which version of ghc are you testing on? I guess, it's more recent than mine. 6.10.3. But I think if you compiled it with 6.8.*, the library code would

Re: Data.List permutations

2009-08-04 Thread Malcolm Wallace
Your function is not equivalent: perm _|_ = _|_ permutations _|_ = _|_ : _|_ I have a vague memory that the library version diagonalises properly, so that if you give it a lazy infinite input, it still generates sensible output lazily. If so, this important property should be noted in