concept game state in category idris

appears as: game states, game state, game state
Type-Driven Development with Idris

This is an excerpt from Manning's book Type-Driven Development with Idris.

Processing a guess will return a game state with one type if the guess is correct, and a different type if the guess is incorrect. You can use the Either generic type to represent this. Remember that Either is a generic type defined in the Prelude that carries a value of two possible types:

Listing 12.20. Extending the Command type to support game state (ArithState.idr)

  

Although the type allows you to express the game state precisely and helps you give types to intermediate operations (such as processing a guess), it doesn’t guarantee that the implementation follows the rules of the game correctly. In the preceding implementation, it’s impossible for the player to win!

Displaying the game state should display the known letters in the target word and the number of guesses remaining. For example, if the target word is TESTING and you’ve already guessed T, with six guesses remaining, ShowState should display the following: