Sukit Tretriluxana wrote:
Dear expert Haskellers,
I am a newbie to Haskell and try to write several algorithms with it.
One of them is the string permutation which generates all possible
permutations using the characters in the string.
While I could hardly be called an expert haskeller, here's my version:
permute :: [a] -> [[a]]
permute [] = [[]]
permute list = concat $ map (\(x:xs) -> map (x:) (permute xs)) (take
(length list) (unfoldr (\x -> Just (x, tail x ++ [head x])) list))
HTH
Martin
_______________________________________________
Haskell mailing list
Haskell@haskell.org
http://www.haskell.org/mailman/listinfo/haskell