
10 Dec
2006
10 Dec
'06
7:32 a.m.
Andrew Savige wrote:
Finally, and please don't laugh, in Haskell (GHC):
reverseWords :: String -> String reverseWords xs = (concat (intersperse " " (reverse (words xs))))
which does appear to work correctly. However, I would like to do justice to Haskell as a language -- and given that my clumsy Haskell is not written in expert style -- I'm hoping that someone on this list might offer a better, faster, or more idiomatic Haskell solution to this little problem.
What about just: reverseWords = concat . intersperse " " . reverse . words -- http://www.metamilk.com