Haskell: Gluing a char and a list together?
Posted
by Vincent
on Stack Overflow
See other posts from Stack Overflow
or by Vincent
Published on 2010-05-19T15:11:41Z
Indexed on
2010/05/19
15:30 UTC
Read the original article
Hit count: 233
haskell
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 type
Char'`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.
© Stack Overflow or respective owner