
On 7 June 2013 01:21, Denis Kasak
On 7 June 2013 01:14, Tim Perry
wrote: Denis' version doesn't work for names containing hyphens or apostrophes. The original works for both.... However, the original explicitly assumes there are always at least two names and gives erroneous data if there are more than two. Output below shows the failure on hyphenated names.
Well, yes, I explicitly did not want to dwell on my (potential) implicit assumptions and just handled the cases that where visible in the problem example or were made explicit by the original poster. Adding additional special behaviour for hypens and apostrophes would be trivial, though, by further modifying the isAlphaOrSpace predicate to include the new special characters.
For instance, from a ghci session:
let s = " \" John Doe-Smith \" " let (|||) = liftM2 (||) let predicate = isAlpha ||| isSpace ||| (== '-') ||| (== '\'') let fs = unwords . words . takeWhile predicate . dropWhile (not . isAlpha) $ s fs "John Doe-Smith"
-- Denis Kasak