Skip to content

Instantly share code, notes, and snippets.

@joseph-montanez
Created August 12, 2013 05:10
Show Gist options
  • Save joseph-montanez/6208361 to your computer and use it in GitHub Desktop.
Save joseph-montanez/6208361 to your computer and use it in GitHub Desktop.
compiles but does nothing?
data GameState = Running | Paused | Stopped
data World = World {
gameState :: GameState,
loopCount :: Int
}
gameloop world =
case gameState world of
Running -> do
userInput <- getLine
case userInput of
"pause" -> gameloop world { gameState = Paused }
"stop" -> gameloop world { gameState = Stopped }
_ -> do
let newCount = loopCount world + 1
putStrLn ("You typed: " ++ userInput)
putStrLn ("I've looped " ++ show newCount ++ " times")
gameloop world { loopCount = newCount }
Paused -> gameloop world
Stopped -> return world
main = do
let world = gameloop $ World Running 0
putStrLn ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment