I tried to implement words function from Data.List, but my implementation doesn't work exactly as I wish.
For example, if the function's input is "tere vana kere" then the output is ["vana", "kere"] and it misses the first word. But when I add space in front of my input " tere vana kere" then the output is correct ["tere", "vana", "kere"]
Could someone point out the problem. Thank You
words' :: String -> [String]
words' xs = snd $ foldr (\x acc -> if isSpace x then
if null (fst acc) then
acc
else
([], (fst acc): (snd acc))
else
(x:fst acc, snd acc)
) ([],[]) xs