I want to read a String and toUpper all the characters.
import Data.Char
main = do
a <- getLine
b <- getLine
map toUpper a
if (a == b)
then print 0
else if (a < b)
then print (-1)
else print 1
Then I got this
Couldn't match expected type `IO a0' with actual type `[b0]'
In the return type of a call of `map'
In a stmt of a 'do' expression: map toUpper a
In the expression:
do { a <- getLine;
b <- getLine;
map toUpper a;
if (a == b) then
print 0
else
if (a < b) then print (- 1) else print 1 }
Hou can I use map with a String got from getLine?
Or there is another way to read a String and toUpper all the characters ?
You are not assigning the “result” of your
mapcall to anything at all. This is causing the type error you are getting, which is telling you that you are trying to return a string (the result of themapcall), when it really needs to be someIOtype.A direct fix would look something like this:
If you use
fmapyou cantoUpperall the chars and get the line of input at the same time (preventing the need for ac).