monad-primitive-0.1: Type class for monad transformers stack with pirimitive base monad.

Portabilityportable
Stabilityexperimental
Maintaineralexey.skladnoy@gmail.com
Safe HaskellNone

Data.PrimRef

Contents

Description

Mutable references in monads which are instances of MonadPrim.

Synopsis

PrimRefs

data PrimRef m a Source

Mutable variable which full analog of IORef or STRef but could use either of the monads. Unfortunately there's no way to convert PrimRef to STRef or IORef.

newPrimRef :: PrimMonad m => a -> m (PrimRef m a)Source

Create new mutable variable with initial value a.

readPrimRef :: PrimMonad m => PrimRef m a -> m aSource

Read value of PrimRef.

writePrimRef :: PrimMonad m => PrimRef m a -> a -> m ()Source

Write value to PrimRef.

modifyPrimRef :: PrimMonad m => PrimRef m a -> (a -> a) -> m ()Source

Modify content of PrimRef using function.

modifyPrimRef' :: PrimMonad m => PrimRef m a -> (a -> a) -> m ()Source

Modify content of PrimRef using function and evaluate result of function application to WHNF before storing it in the variable.