从chinaunix的fp板上看到的, 摘过来 原载自 http://bbs2.chinaunix.net/thread-1289053-1-2.html 作者为drunkedcat和MMMIX
组合:
combination :: [a] -> [[a]]
combination [] = [[]]
combination (x:xs) = (map (x:) (combination xs) )++ (combination xs)
排列:
permutation :: Eq a => [a] -> [[a]]
permutation [] = [[]]
permutation xs = concatMap (\x -> map (x:) $ permutation (delete x xs)) xs