
Off the top of my head:
separate :: String -> [String]
separate [] = []
separate s =
case break (',' ==) s of
(s,[]) -> [s]
(s,',':s') -> s : separate s'
_ -> error "how did we get here?"
There is at least one cunning rewriting with foldl, I think, but I
think this version is clearer.
/g
On 6/12/06, Sara Kenedy
Hi all,
I want to write a function to separate a string into a list of strings separated by commas.
Example: separate :: String -> [String]
separate "Haskell, Haskell, and Haskell" = ["Haskell", "Haskell", "and Haskell"]
If anyone has some ideas, please share with me. Thanks.
S. _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- We have lingered in the chambers of the sea By sea-girls wreathed with seaweed red and brown Till human voices wake us, and we drown.