Learn You a Haskell shows the lines function:
It takes a string and returns every line of that string in a separate list.
Example:
>lines' "HELLO\nWORLD\nHOWAREYOU" ["HELLO","WORLD","HOWAREYOU"]
Here's my implementation:
lines' :: String -> [String]
lines' [] = []
lines' xs = lines'' xs []
where lines'' [] ys = ys : []
lines'' (x:xs) ys
| x == '\n' = ys : lines'' xs []
| otherwise = lines'' xs (ys ++ [x])
Please critique it. Also, when using an accumulator value (such as ys in lines''), I don't know how to use the : function instead of ++.