concept machine in category idris

This is an excerpt from Manning's book Type-Driven Development with Idris.
An ATM supports several basic operations, each of which is valid only when the machine is in a specific state, and each of which might change the state of the machine, as illustrated in figure 1.2. These are the basic operations:
Figure 1.2. The states and valid operations on an ATM. Each operation is valid only in specific states and can change the state of the machine. CheckPIN changes the state only if the entered PIN is correct.
![]()
Whether an operation is valid or not depends on the state of the machine. For example, InsertCard is valid only in the Ready state, because that’s the only state where there’s no card already in the machine. Also, Dispense is valid only in the Session state, because that’s the only state where there’s a validated card in the machine.
Furthermore, executing one of these operations can change the state of the machine. For example, InsertCard changes the state from Ready to CardInserted, and CheckPIN changes the state from CardInserted to Session, provided that the entered PIN is correct.
vend : MachineIO (pounds, chocs) vend {pounds = S p} {chocs = S c} #1 = do Vend Display "Enjoy!" machineLoop vend {pounds = Z} #2 = do Display "Insert a coin" machineLoop vend {chocs = Z} #3 = do Display "Out of stock" machineLoop refill : (num : Nat) -> MachineIO (pounds, chocs) refill {pounds = Z} num #4 = do Refill num machineLoop refill _ = do Display "Can't refill: Coins in machine" machineLoop