Comma quibbling: Difference between revisions
m
→{{header|Haskell}}: Tidied
m (→{{header|Haskell}}: Tidied) |
|||
Line 2,013:
Or, defining just two cases, and drawing more on standard libraries than on hand-crafted pattern-matching and recursion:
<syntaxhighlight lang="haskell">import Data.List (intercalate)
--------------------- COMMA QUIBBLING --------------------
quibble :: [String] -> String
quibble ws@(_ : _ : _) =
intercalate
( [intercalate ", " . reverse . tail, head]
" and "▼
)
quibble xs = concat xs
--------------------------- TEST -------------------------
main :: IO ()
main =
mapM_ (putStrLn . (`intercalate` ["{", "}"]) . quibble) $
[[], ["ABC"], ["ABC", "DEF"], ["ABC", "DEF", "G", "H"]]
<$> [ "One two three four",
</syntaxhighlight>▼
"Me myself I",
"Jack Jill",
"Loner"
]
▲ )</syntaxhighlight>
{{Out}}
<pre>{}
|