Since next_coin is to be repeated until it is given an amount of 0, we can write

recurs :: Int -> StMach Int 
recurs amt = 
   if amt==0
      then return amt
      else next_coin amt >>= recurs

So recurs can be used the same places next_coin can. Only it will repeat next_coin the right number of times.

Although we won't be implementing the dispense function, we will need a stub to run our program. The basic idea is to do this

putStrLn ("dispense "++(show i)++" cents")

but that will not work in the context of a StMach monad. We need to lift to the wrapping IO monad this way: