So I have this code here:
toWords :: String -> [String]
toWords "" = []
toWords (nr1 : rest)
| nr1 == ' ' = toWords rest
| otherwise = [nr1] : toWords rest
The "toWords" function should simply remove all spaces and return a list with all the words. But this happens:
*Main> toWords "How are you?"
["H","o","w","a","r","e","y","o","u","?"]
Your type should be String -> [String] or [Char] -> [[Char]].
Your input is a string (a list of chars) your output a list of string (a list of chars of chars).
Your type here means it maps a string to ANY type, this is not true.
Edit: alternatively you can use:
Which is polymorphic and splits a list by any separator. (code not tested though) so
splitBy "string of words" ' 'should return [“string”,”of”,”words”].FINALLY, this was annoying and had an obvious and stupid error of [] in lieu of [[]] the functional version is:
Such that:
splitBy "List of things" ' ' ===> ["list","of","things"]