目标是将 Haskell 中的 Nim 游戏编码为学校作业。我是 Haskell 的新手,当我尝试读取输入时会出现奇怪的行为。
目标是读取两个整数。而不是打印第一条消息,然后提示然后继续第二条消息,它只打印两条消息,我无法提供正确的输入。这里有什么问题?
type Board = [Int] -- The board
type Heap = Int -- id of heap
type Turn = (Int, Int) -- heap and number of stars to remove
readInt :: String -> IO Int
readInt msg = do putStr (msg ++ "> ")
inp <- getChar
let x = ord inp
return x
readTurn :: Board -> IO(Turn)
readTurn b = do heap <- readInt "Select heap:"
amt <- readInt "Select stars:"
print heap
print amt
return(heap, amt)