Haskell: Gluing a char and a list together?
- by Vincent
So I have this code here:
toWords :: String - [a]
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 I keep getting this error:
test.hs:5:18:
Couldn't match expected type a' against inferred typeChar'
`a' is a rigid type variable bound by
the type signature for `toWords' at test.hs:1:22
In the first argument of `(:)', namely `nr1'
In the expression: nr1 : toWords rest
In the definition of `toWords':
toWords (nr1 : rest)
| nr1 == ' ' = toWords rest
| otherwise = nr1 : toWords rest Failed, modules loaded:
none.