idiom for producing comma-seperated lists?
Fri, 8 Aug 2003 14:55:43 +0100
Antony Courtney <firstname.lastname@example.org> writes:
> I often need to format a list of strings using some character as a
> *seperator* rather than a terminator for the items. Is there some
> simple combinator or idiom from the Prelude or standard libraries that
> could be used for this purpose?
List.intersperse :: a -> [a] -> [a]
> -- Example: format a list of strings, using a comma as a seperator:
> mkSepStr :: [String] -> String
> mkSepStr xs = foldrs (\x s -> x ++ ", " ++ s) "" xs
mkSepStr :: [String] -> String
mkSepStr = concat . intersperse ", "