concept Command in category idris

appears as: Command, Commd
Type-Driven Development with Idris

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

You’ll therefore define a Command data type, which is a union type representing the possible commands and their arguments. Put the following definition in DataStore.idr above processInput:

  • Instead of passing the current score as an argument to the quiz function, maintaining the state by hand, we’ll extend the Command type with commands for giving access to the current score and the difficulty setting.
  • 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.

    The next listing shows how you can extend the Command data type to include these commands. There’s no need to update ConsoleIO, because it merely sequences Commands.

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