I want to create operations that may fail, but there is a way to roll back.
For example, an external call to book a hotel room and an external call to pay by credit card. Both of these calls may fail, for example, there are no rooms left, an invalid credit card. Both have ways to lean back - cancel a hotel room, cancel a loan fee.
- Is there a name for this type of (not real) atom. Whenever I look for a haskell transaction, I get
STM. - Is there an abstraction, a way to build them, or a library in haskell or in any other language?
I feel that you can write a monad Atomic Tthat will track these operations and roll them back if there is an exception.
Edit:
These operations may be IO. If the operations were only memory operations, as the two answers show, STM will suffice.
For example, hotel reservations will be through HTTP requests. Database operations, such as inserting records through a socket connection.
In the real world, there is a grace period for irreversible operations before the operation is completed. credit card payments and hotel reservations can be settled at the end of the day, and therefore, until this point, the penalty is canceled.
source
share