[email protected]
[Top] [All Lists]

[Haskell-cafe] Review request for my permutations implementation

Subject: [Haskell-cafe] Review request for my permutations implementation
From: CK Kashyap
Date: Thu, 7 Jan 2010 00:37:42 -0800 PST
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)
where
_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 ...


Regards,
Kashyap


      

_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

<Prev in Thread] Current Thread [Next in Thread>