HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Moduleunliftio-0.2.25.1Haskell2010

UnliftIO.STM

Lifted version of Control.Concurrent.STM

  • 6 types
  • 63 values

Core

5 declarations
newtypenewtype STM a
#

A monad supporting atomic memory transactions.

Instances11Monad, Functor, MonadFix, Applicative, Alternative, MonadPlus, …
  • Monad STMDefined in ghc-internal-9.1003.0 · GHC.Internal.Conc.Sync
  • Functor STMDefined in ghc-internal-9.1003.0 · GHC.Internal.Conc.Sync
  • MonadFix STMDefined in stm-2.5.3.1 · Control.Monad.STM · orphan
  • Applicative STMDefined in ghc-internal-9.1003.0 · GHC.Internal.Conc.Sync
  • Alternative STMDefined in ghc-internal-9.1003.0 · GHC.Internal.Conc.Sync

    Takes the first non-retrying STM action.

  • MonadPlus STMDefined in ghc-internal-9.1003.0 · GHC.Internal.Conc.Sync

    Takes the first non-retrying STM action.

  • MonadCatch STMDefined in exceptions-0.10.9 · Control.Monad.Catch
  • MonadThrow STMDefined in exceptions-0.10.9 · Control.Monad.Catch
  • MArray TArray e STMDefined in stm-2.5.3.1 · Control.Concurrent.STM.TArray
  • Semigroup a => Semigroup (STM a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Conc.Sync
  • Monoid a => Monoid (STM a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Conc.Sync
valueorElse :: STM a -> STM a -> STM a
#

Compose two alternative STM actions (GHC only).

If the first action completes without retrying then it forms the result of the orElse. Otherwise, if the first action retries, then the second action is tried in its place. If both actions retry then the orElse as a whole retries.

TVar

12 declarations
datadata TVar a
#

Shared memory locations that support atomic memory transactions.

Instances1Eq
  • Eq (TVar a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Conc.Sync
valuemodifyTVar :: TVar a -> (a -> a) -> STM ()
#

Mutate the contents of a TVar. N.B., this version is non-strict.

valuestateTVar :: TVar s -> (s -> (a, s)) -> STM a
#

Like modifyTVar' but the function is a simple state transition that can return a side value which is passed on as the result of the STM.

TMVar

15 declarations
newtypenewtype TMVar a
#

A TMVar is a synchronising variable, used for communication between concurrent threads. It can be thought of as a box, which may be empty or full.

Instances1Eq
  • Eq (TMVar a)Defined in stm-2.5.3.1 · Control.Concurrent.STM.TMVar
valuewriteTMVar :: TMVar a -> a -> STM ()
#

Non-blocking write of a new value to a TMVar Puts if empty. Replaces if populated.

TChan

14 declarations
datadata TChan a
#

TChan is an abstract type representing an unbounded FIFO channel.

Instances1Eq
  • Eq (TChan a)Defined in stm-2.5.3.1 · Control.Concurrent.STM.TChan
valuenewBroadcastTChan :: STM (TChan a)
#

Create a write-only TChan. More precisely, readTChan will retry even after items have been written to the channel. The only way to read a broadcast channel is to duplicate it with dupTChan.

Consider a server that broadcasts messages to clients:

serve :: TChan Message -> Client -> IO loop
serve broadcastChan client = do
    myChan <- dupTChan broadcastChan
    forever $ do
        message <- readTChan myChan
        send client message

The problem with using newTChan to create the broadcast channel is that if it is only written to and never read, items will pile up in memory. By using newBroadcastTChan to create the broadcast channel, items can be garbage collected after clients have seen them.

valuedupTChan :: TChan a -> STM (TChan a)
#

Duplicate a TChan: the duplicate channel begins empty, but data written to either channel from then on will be available from both. Hence this creates a kind of broadcast channel, where data written by anyone is seen by everyone else.

valuecloneTChan :: TChan a -> STM (TChan a)
#

Clone a TChan: similar to dupTChan, but the cloned channel starts with the same content available as the original channel.

valuepeekTChan :: TChan a -> STM a
#

Get the next value from the TChan without removing it, retrying if the channel is empty.

valueunGetTChan :: TChan a -> a -> STM ()
#

Put a data item back onto a channel, where it will be the next item read.

TQueue

10 declarations
datadata TQueue a
#

TQueue is an abstract type representing an unbounded FIFO channel.

Instances1Eq
  • Eq (TQueue a)Defined in stm-2.5.3.1 · Control.Concurrent.STM.TQueue
valuepeekTQueue :: TQueue a -> STM a
#

Get the next value from the TQueue without removing it, retrying if the channel is empty.

valueunGetTQueue :: TQueue a -> a -> STM ()
#

Put a data item back onto a channel, where it will be the next item read.

TBQueue

13 declarations
datadata TBQueue a
#

TBQueue is an abstract type representing a bounded FIFO channel.

Instances1Eq
  • Eq (TBQueue a)Defined in stm-2.5.3.1 · Control.Concurrent.STM.TBQueue
valuepeekTBQueue :: TBQueue a -> STM a
#

Get the next value from the TBQueue without removing it, retrying if the channel is empty.

valueunGetTBQueue :: TBQueue a -> a -> STM ()
#

Put a data item back onto a channel, where it will be the next item read. Blocks if the queue is full.