0
我是Haskell的初学者,我被困在IO问题,我无法解决。Haskell - 比较与字符的IO字符
我正在做一个Snake游戏,我唯一需要做的事情就是让用户输入,让蛇移动。因此,这里是我的功能
--Get char
input :: IO Char
input =
hSetEcho stdin False
>> hSetBuffering stdin NoBuffering
>> getChar
myFunction :: IO Char -> Int -> Int
myfunction myChar oldValue
| (myChar == 'q') = 1
| (myChar == 'w') = 2
| (myChar == 'e') = 3
| (myChar == 'r') = 4
| otherwise = oldValue
-- At the beginning of the game, function is called like this
let dir = myFunction input 1 --To give the snake an initial direction
-- The game works with a function Turn that takes an Int as parameter
-- which is the previous direction. let's call it oldDir
let newDir = myFunction input oldDir
-- Then I call Turn again with newDir as parameter
的问题来自于(myChar ==字符)的一部分,是“无法符合预期的类型‘IO字符’与实际类型‘字符’”
如何比较IO Char和Char?
简答:我不行。你能帮我解答更长的问题吗? 这个问题可能被问了很多次,但我仍然坚持这个问题。
预先感谢您的回答!
亲切,
我的首选回答是:在C中,'getchar()'等于''L''? –