I am having trouble to use my function that returns an Either monad in my main :: IO() function. I am able to run my code without using Either, but I now use Either to handle errors. I have the following code:
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 ...
So my code was able to do Gloss.play and so on if my parse-function just returned a. How can I handle Either in the main with IO.
You're close. In your
Right game ->
case, you want to introduce anotherdo
-block, so something like: