Missing a case in permutations:

1
2
3
4
5
6
7
8
9
10
 

let rec selections = function
    | []      -> []
    | x::xs -> (x,xs) :: [ for (y,ys) in selections xs -> (y,x::ys) ]
let rec permutations = function
  | x::[] -> seq [[x]]
  | xs ->  seq { for (y,ys) in selections xs do
                    for zs in permutations ys do yield y::zs }

[link:www.haskell.org]

By on 4/11/2009 6:31 AM ()

Thank you MichaelGG. Should have continued reading on ...
I changed the title, because its not a problem with the sequence expression.

By on 4/11/2009 7:08 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper