I'm have to make a very small game in Haskell for a course I follow. So I created the play-function, but now I have trouble changing it's type signature.
play :: [[String]] -> StateT GameState IO Score play input = do liftIO $ clearScreen (answered, correct) <- get if True then do liftIO $ putStrLn "Well done! Your answer was correct!" liftIO $ putStrLn ("So far, you answered " ++ (show answered) ++ " questions") put (answered + 1, correct + 1) liftIO $ do temp <- getLine putStrLn temp else do liftIO $ putStrLn "I'm sorry, you're wrong..." put (answered + 1, correct) play input Now, please don't mind the if True statement, that's just for testing. Now this function works, but I have to make it work with another type signature to. The type signature of the function play should be:
play :: IO (Either ParseError [[String]]) -> StateT GameState IO Score But I have absolutely no idea on how to use my StateT monad then? How can I do this? The IO (Either ParseError [[String]]) monad is a result of the parseFromFile-function from the missingH-package.
play. Whatever callsparseFromFileshould be deciding, based on that result, whether or not to callplay.[[String]]instead of theIO (Either ParseError [[String]])? I don't have access to the[[String]]rightaway.lift :: IO (Either ParseError [[String]]) -> StateT GameState IO (Either ...)and then use monadic bind (>>=or inside adoblock) on this value. You will still need to deal with theParseError- perhaps throwing an exception or changing your monad toStateT GameState (ErrorT SomeErrorType IO)