mutable-containers-0.1.2.0: Abstactions and concrete implementations of mutable containers

Safe HaskellNone
LanguageHaskell2010

Data.Mutable.PRef

Contents

Description

Use ByteArrays containing one element for mutable references.

This is similar to URefs, but avoids the overhead of storing the length of the Vector, which we statically know will always be 1. This allows it to be a bit faster.

Motivated by: http://stackoverflow.com/questions/27261813/why-is-my-little-stref-int-require-allocating-gigabytes and ArrayRef.

Synopsis

Types

data PRef s a Source

A primitive ByteArray reference, supporting any monad.

Instances

Prim a => MutableRef (PRef s a) 
MutableContainer (PRef s a) 
type RefElement (PRef s a) = a 
type MCState (PRef s a) = s 

type IOPRef = PRef (PrimState IO) Source

A primitive ByteArray IO reference.

Functions

asPRef :: PRef s a -> PRef s a Source

class MutableContainer c => MutableRef c where Source

Associated Types

type RefElement c Source

Methods

newRef :: (PrimMonad m, PrimState m ~ MCState c) => RefElement c -> m c Source

readRef :: (PrimMonad m, PrimState m ~ MCState c) => c -> m (RefElement c) Source

writeRef :: (PrimMonad m, PrimState m ~ MCState c) => c -> RefElement c -> m () Source

modifyRef :: (PrimMonad m, PrimState m ~ MCState c) => c -> (RefElement c -> RefElement c) -> m () Source

modifyRef' :: (PrimMonad m, PrimState m ~ MCState c) => c -> (RefElement c -> RefElement c) -> m () Source

Instances