我无法使用在我的 main :: IO() 函数中返回 Either monad 的函数。我可以在不使用 Either 的情况下运行我的代码,但我现在使用 Either 来处理错误。我有以下代码:
parse :: Parser a -> String -> Either TypeRep a
parseFile :: String -> Either TypeRep Game
main :: IO()
main = do
content <- readFile "file.txt"
let info = parseFile content
case info of
Left e -> error $ show e
Right game -> let level = makeGame game
Gloss.play ... level ...
因此,如果我的解析函数刚刚返回 a,我的代码就能够执行 Gloss.play 等等。我如何使用 IO 在主中处理 Either。