[Haskell-cafe] Review request for my permutations implementation

CK Kashyap ck_kashyap at yahoo.com
Thu Jan 7 03:37:42 EST 2010

Hi All,

I've written this piece of code to do permutations -

perms :: String -> [String]
perms []= []
perms (x:[])= [[x]]
perms (x:xs)= concat (f [x] (perms xs))

spread :: String -> String -> [String] -- interpolate first string at various positions of second string
spread str1 str2 = _spread str1 str2 (length str2)
_spread str1 str2 0= [str1 ++ str2]
_spread str1 str2 n= [(take n str2) ++ str1 ++ (drop n str2)] ++ (_spread str1 str2 (n-1))

f xs = map (spread xs)

The number of outcomes seem to indicate that correctness of the algo .. however, I'd be very obliged
if I could get some feedback on the Haskellness etc of this ... also any performance pointers ...



More information about the Haskell-Cafe mailing list