STM package:stm

Software Transactional Memory: a modular composable concurrency abstraction. See
Software Transactional Memory: a modular composable concurrency abstraction. See This module only defines the STM monad; you probably want to import Control.Concurrent.STM (which exports Control.Monad.STM). Note that invariant checking (namely the always and alwaysSucceeds functions) has been removed. See ticket #14324 and the removal proposal. Existing users are encouraged to encapsulate their STM operations in safe abstractions which can perform the invariant checking without help from the runtime system.
A monad supporting atomic memory transactions.
Software Transactional Memory Software Transactional Memory, or STM, is an abstraction for concurrent communication. The main benefits of STM are composability and modularity. That is, using STM you can write concurrent abstractions that can be easily composed with any other abstraction built using STM, without exposing the details of how your abstraction ensures safety. This is typically not the case with other forms of concurrent communication, such as locks or MVars.
Exception handling within STM actions. catchSTM m f catches any exception thrown by m using throwSTM, using the function f to handle the exception. If an exception is thrown, any changes made by m are rolled back, but changes prior to m persist.
A variant of throw that can only be used within the STM monad. Throwing an exception in STM aborts the transaction and propagates the exception. If the exception is caught via catchSTM, only the changes enclosed by the catch are rolled back; changes made outside of catchSTM persist. If the exception is not caught inside of the STM, it is re-thrown by atomically, and the entire STM is rolled back. Although throwSTM has a type that is an instance of the type of throw, the two functions are subtly different:
throw e    `seq` x  ===> throw e
throwSTM e `seq` x  ===> x
The first example will cause the exception e to be raised, whereas the second one won't. In fact, throwSTM will only cause an exception to be raised when it is used within the STM monad. The throwSTM variant should be used in preference to throw to raise an exception within the STM monad because it guarantees ordering with respect to other STM operations, whereas throw does not.