zoom-refs- Zoom (~ Functor) and pairing (~ Applicative) for mutable references.

Safe HaskellNone




data TVar a where Source


Leaf :: TVar x -> ALens' x a -> TVar a 
Branch :: TVar x -> TVar y -> ALens' (x, y) a -> TVar a 

zoomTVar :: ALens' a b -> TVar a -> TVar b Source

newTVar :: a -> STM (TVar a) Source

newTVarIO :: a -> IO (TVar a) Source

pairTVars :: TVar a -> TVar b -> TVar (a, b) Source

modifyTVar :: TVar a -> (a -> a) -> STM () Source

modifyTVar' :: TVar a -> (a -> a) -> STM () Source

writeTVar :: TVar a -> a -> STM () Source

swapTVar :: TVar a -> a -> STM a Source

data STM a :: * -> *

A monad supporting atomic memory transactions.

atomically :: STM a -> IO a

Perform a series of STM actions atomically.

You cannot use atomically inside an unsafePerformIO or unsafeInterleaveIO. Any attempt to do so will result in a runtime error. (Reason: allowing this would effectively allow a transaction inside a transaction, depending on exactly when the thunk is evaluated.)

However, see newTVarIO, which can be called inside unsafePerformIO, and which allows top-level TVars to be allocated.