IOSpec-0.3.1.2: A pure specification of the IO monad.

Safe Haskell | Safe-Inferred
Language | Haskell98

Test.IOSpec.STM

Contents

- The specification of STM
- Atomically
- The STM monad

Synopsis

- data STMS a
- atomically :: forall (f :: Type -> Type) a. STMS :<: f => STM a -> IOSpec f a
- data STM a
- data TVar a
- newTVar :: Typeable a => a -> STM (TVar a)
- readTVar :: Typeable a => TVar a -> STM a
- writeTVar :: Typeable a => TVar a -> a -> STM ()
- retry :: STM a
- orElse :: STM a -> STM a -> STM a
- check :: Bool -> STM ()

# The specification of STM

data STMS a Source #

An expression of type `IOSpec `STMS` a` corresponds to an `IO` computation that may use `atomically` and returns a value of type `a`.

By itself, `STMS` is not terribly useful. You will probably want to use `IOSpec (ForkS :+: STMS)`.

#### Instances

Instances details

Executable STMS Source # |
Instance details Defined in Test.IOSpec.STM Methods step :: STMS a -> VM (Step a) Source #
Functor STMS Source # |
Instance details Defined in Test.IOSpec.STM Methods fmap :: (a -> b) -> STMS a -> STMS b Source # (<$) :: a -> STMS b -> STMS a Source #

# Atomically

atomically :: forall (f :: Type -> Type) a. STMS :<: f => STM a -> IOSpec f a Source #

The `atomically` function atomically executes an `STM` action.

# The STM monad

data STM a Source #

#### Instances

Instances details

Applicative STM Source # |
Instance details Defined in Test.IOSpec.STM Methods pure :: a -> STM a Source # (<*>) :: STM (a -> b) -> STM a -> STM b Source # liftA2 :: (a -> b -> c) -> STM a -> STM b -> STM c Source # (*>) :: STM a -> STM b -> STM b Source # (<*) :: STM a -> STM b -> STM a Source #
Functor STM Source # |
Instance details Defined in Test.IOSpec.STM Methods fmap :: (a -> b) -> STM a -> STM b Source # (<$) :: a -> STM b -> STM a Source #
Monad STM Source # |
Instance details Defined in Test.IOSpec.STM Methods (>>=) :: STM a -> (a -> STM b) -> STM b Source # (>>) :: STM a -> STM b -> STM b Source # return :: a -> STM a Source #

data TVar a Source #

A `TVar` is a shared, mutable variable used by STM.

newTVar :: Typeable a => a -> STM (TVar a) Source #

The `newTVar` function creates a new transactional variable.

readTVar :: Typeable a => TVar a -> STM a Source #

The `readTVar` function reads the value stored in a transactional variable.

writeTVar :: Typeable a => TVar a -> a -> STM () Source #

The `writeTVar` function overwrites the value stored in a transactional variable.

retry :: STM a Source #

The `retry` function abandons a transaction and retries at some later time.

orElse :: STM a -> STM a -> STM a Source #

The `orElse` function takes two `STM` actions `stm1` and `stm2` and performs `stm1`. If `stm1` calls `retry` it performs `stm2`. If `stm1` succeeds, on the other hand, `stm2` is not executed.

check :: Bool -> STM () Source #

The `check` function checks if its boolean argument holds. If the boolean is true, it returns (); otherwise it calls `retry`.