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

Safe HaskellSafe
LanguageHaskell98

Data.StateRef.Types

Synopsis

Documentation

data Ref m a where Source #

A simple reference type, hiding the complexity of all these type classes, since most of the time the only thing you care about is that you want a reference. The full complexity is still there, though, so FFI types or other reference-like things can still be made into Refs.

Constructors

Ref :: ModifyRef sr m a => !sr -> Ref m a 

class WriteRef sr m a | sr -> a where Source #

Minimal complete definition

writeReference

Methods

writeReference :: sr -> a -> m () Source #

Replace the existing value of the given reference with the provided value.

Instances

WriteRef sr m a => WriteRef (UnsafeModifyRef sr) m a Source # 

Methods

writeReference :: UnsafeModifyRef sr -> a -> m () Source #

Monad m => WriteRef (Accessor m a) m a Source # 

Methods

writeReference :: Accessor m a -> a -> m () Source #

Monad m => WriteRef (Setter m a) m a Source # 

Methods

writeReference :: Setter m a -> a -> m () Source #

class ReadRef sr m a | sr -> a where Source #

Minimal complete definition

readReference

Methods

readReference :: sr -> m a Source #

Get the current value referenced by the given state reference.

Instances

ReadRef sr m a => ReadRef (UnsafeModifyRef sr) m a Source # 
Monad m => ReadRef (Accessor m a) m a Source # 

Methods

readReference :: Accessor m a -> m a Source #

Monad m => ReadRef (Getter m a) m a Source # 

Methods

readReference :: Getter m a -> m a Source #

class (ReadRef sr m a, WriteRef sr m a) => ModifyRef sr m a | sr -> a where Source #

Minimal complete definition

atomicModifyReference, modifyReference

Methods

atomicModifyReference :: sr -> (a -> (a, b)) -> m b Source #

Atomically modify the contents of a reference. This is implemented in a separate class (rather than a function with context (ReadRef sr m a, WriteRef sr m a)) because in most cases the default implementation cannot act atomically.

modifyReference :: sr -> (a -> a) -> m () Source #

Same thing, but don't thread out the extra return. Could perhaps be implemented slightly more efficiently than atomicModifyReference in many cases. Note that implementations are expected to be atomic, if at all possible, but not strictly required to be.

Instances

(Monad m, ReadRef sr m a, WriteRef sr m a) => ModifyRef (UnsafeModifyRef sr) m a Source # 

Methods

atomicModifyReference :: UnsafeModifyRef sr -> (a -> (a, b)) -> m b Source #

modifyReference :: UnsafeModifyRef sr -> (a -> a) -> m () Source #

defaultAtomicModifyReference :: (WriteRef sr m a, ReadRef sr m t, Monad m) => sr -> (t -> (a, b)) -> m b Source #

Default implementation of atomicModifyReference in terms of readReference and writeReference

defaultModifyReference :: (WriteRef sr m a, ReadRef sr m t, Monad m) => sr -> (t -> a) -> m () Source #

Default implementation of modifyReference in terms of readReference and writeReference

class NewRef sr m a | sr -> a where Source #

Minimal complete definition

newReference

Methods

newReference :: a -> m sr Source #

Construct a new reference to the provided value.

class HasRef m where Source #

Minimal complete definition

newRef

Methods

newRef :: a -> m (Ref m a) Source #

Construct a new mutable reference (of an unspecified implementation type) containing the provided value.