concept arithmetic quiz in category idris

This is an excerpt from Manning's book Type-Driven Development with Idris.
Earlier, the questions were too predictable, but now they’re perhaps a little too hard for most of us! Furthermore, in the preceding example, the result has even overflowed the bounds of an Int, so the reported answer is incorrect. Instead, the next listing shows one way to process the results of randoms so that they’re within reasonable bounds for an arithmetic quiz.
Previously, we’ve used types to describe interactive programs in terms of sequences of commands, using IO in chapter 5 and ConsoleIO in chapter 11. Stateful programs can work in the same way, using types to describe the operations a stateful program can perform. We’ll begin by looking at the generic State type defined in the Idris library and then at how we can define types like State ourselves. Finally, we’ll look at how we can structure a complete application with state, refining the arithmetic quiz from chapter 11.
Using your new Command type and the GameState record, you can implement the arithmetic quiz by reading and updating the state as necessary. The next listing shows an outline of the quiz implementation, leaving holes for correct and wrong, which, respectively, process a correct answer and a wrong answer.
In chapter 11, you defined a Command data type, representing the commands you could use in console I/O programs, and a ConsoleIO type, representing possibly infinite interactive processes. You used this to implement an arithmetic quiz, presenting multiplication problems for a user to answer. Like State, which describes the operations Get and Put for reading and writing state, Command describes the operations GetLine and PutStr for reading from and writing to the console. The following listing recaps the definitions of Command and ConsoleIO.