RosettaCodeData/Task/Comma-quibbling/Haskell/comma-quibbling-2.hs
2017-09-25 22:28:19 +02:00

15 lines
433 B
Haskell

import Data.List (intercalate)
quibble :: [String] -> String
quibble ws
| length ws > 1 =
intercalate
" and "
([intercalate ", " . reverse . tail, head] <*> [reverse ws])
| otherwise = concat ws
main :: IO ()
main =
mapM_ (putStrLn . (`intercalate` ["{", "}"]) . quibble) $
[[], ["ABC"], ["ABC", "DEF"], ["ABC", "DEF", "G", "H"]] ++
(words <$> ["One two three four", "Me myself I", "Jack Jill", "Loner"])