I want to implement a Haskell function wordToken that splits a string of words into a list of strings including the fullstops and commas
For example "the man saw." should result in ["the", "man","saw","."]
So what I did is check if the Char is a comma or fullstop , then just add it as is. Then if its a Char and then a Char , add them both. Else if its a Char and then a Space, add it and continue to the rest of the list. But I'm not sure how do I tell it separate the words themselves , or when I add a char to a char then thats a new string
wordToken []= " "
wordToken (x:y:z) | x==',' || x=='.' = " "(++)x:wordToken( y:z)
| x/='\n' && y/='\n'= " "(++)x(++)y(++)wordToken z
| x/='\n' && y=='\n'= " "(++)x:wordToken z
| otherwise = wordToken z
I also tried to use the words function and just add the part of the punctuation but it gave me a type mismatch wordToken (x:xs) | x=='.' || x==',' = 'x':wordToken xs | otherwise =words (x:xs)