stateref-0.3: Abstraction for things that work like IORef.

Data.MRef.Instances

Description

This module exports no new symbols of its own. It defines basic class instances for creating, reading, and writing MVars, and re-exports MVar.

Synopsis

Documentation

data MVar a

An MVar (pronounced "em-var") is a synchronising variable, used for communication between concurrent threads. It can be thought of as a a box, which may be empty or full.

Instances

Eq (MVar a) 
MonadIO m => PutMRef (MVar a) m a 
MonadIO m => TakeMRef (MVar a) m a 
MonadIO m => NewMRef (MVar a) m a 
MonadIO m => NewRef (MVar a) m (Maybe a) 

class Monad m => MonadIO m where

Monads in which IO computations may be embedded. Any monad built by applying a sequence of monad transformers to the IO monad will be an instance of this class.

Instances should satisfy the following laws, which state that liftIO is a transformer of monads:

Methods

liftIO :: IO a -> m a

Lift a computation from the IO monad.

Instances

data STM a

A monad supporting atomic memory transactions.

Instances

Monad STM 
Functor STM 
Typeable1 STM 
MonadPlus STM 
HasMRef STM 
HasRef STM 
PutMRef (TVar (Maybe a)) STM a 
PutMRef (TMVar a) STM a 
TakeMRef (TVar (Maybe a)) STM a 
TakeMRef (TMVar a) STM a 
NewMRef (TVar (Maybe a)) STM a 
NewMRef (TMVar a) STM a 
NewRef (TVar a) STM a 
ModifyRef (TVar a) STM a 
MonadIO m => ReadRef (STM a) m a 
ReadRef (STM a) STM a 
ReadRef (TVar a) STM a 
WriteRef (TVar a) STM a 
NewRef (TMVar a) STM (Maybe a) 
ReadRef (TMVar a) STM (Maybe a) 
PutMRef (MRef STM a) IO a 
TakeMRef (MRef STM a) IO a 
NewMRef (MRef STM a) IO a 
MonadIO m => NewRef (Ref STM a) m a 
MonadIO m => ModifyRef (Ref STM a) m a 
MonadIO m => ReadRef (Ref STM a) m a 
MonadIO m => WriteRef (Ref STM a) m a 

data 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.

Instances

Typeable1 TMVar 
Eq (TMVar a) 
PutMRef (TMVar a) IO a 
PutMRef (TMVar a) STM a 
TakeMRef (TMVar a) IO a 
TakeMRef (TMVar a) STM a 
NewMRef (TMVar a) IO a 
NewMRef (TMVar a) STM a 
MonadIO m => NewRef (TMVar a) m (Maybe a) 
NewRef (TMVar a) STM (Maybe a) 
MonadIO m => ReadRef (TMVar a) m (Maybe a) 
ReadRef (TMVar a) STM (Maybe a) 

data TVar a

Shared memory locations that support atomic memory transactions.

Instances

Typeable1 TVar 
Eq (TVar a) 
PutMRef (TVar (Maybe a)) IO a 
PutMRef (TVar (Maybe a)) STM a 
TakeMRef (TVar (Maybe a)) IO a 
TakeMRef (TVar (Maybe a)) STM a 
NewMRef (TVar (Maybe a)) IO a 
NewMRef (TVar (Maybe a)) STM a 
MonadIO m => NewRef (TVar a) m a 
NewRef (TVar a) STM a 
MonadIO m => ModifyRef (TVar a) m a 
ModifyRef (TVar a) STM a 
MonadIO m => ReadRef (TVar a) m a 
ReadRef (TVar a) STM a 
MonadIO m => WriteRef (TVar a) m a 
WriteRef (TVar a) STM a 

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.