Copyright | (c) 2019 Composewell Technologies |
---|---|
License | BSD3 |
Maintainer | streamly@composewell.com |
Stability | experimental |
Portability | GHC |
Safe Haskell | None |
Language | Haskell2010 |
A mutable variable in a mutation capable monad (IO/ST) holding a Prim
value. This allows fast modification because of unboxed storage.
Multithread Consistency Notes
In general, any value that straddles a machine word cannot be guaranteed to
be consistently read from another thread without a lock. GHC heap objects
are always machine word aligned, therefore, a Var
is also word aligned. On
a 64-bit platform, writing a 64-bit aligned type from one thread and reading
it from another thread should give consistent old or new value. The same
holds true for 32-bit values on a 32-bit platform.
Documentation
Class of types supporting primitive array operations. This includes
interfacing with GC-managed memory (functions suffixed with ByteArray#
)
and interfacing with unmanaged memory (functions suffixed with Addr#
).
Endianness is platform-dependent.
sizeOf#, alignment#, indexByteArray#, readByteArray#, writeByteArray#, setByteArray#, indexOffAddr#, readOffAddr#, writeOffAddr#, setOffAddr#
Instances
Construction
newVar :: forall m a. (MonadMut m, Prim a) => a -> m (Var m a) Source #
Create a new mutable variable.
Write
writeVar :: (MonadMut m, Prim a) => Var m a -> a -> m () Source #
Write a value to a mutable variable.
modifyVar' :: (MonadMut m, Prim a) => Var m a -> (a -> a) -> m () Source #
Modify the value of a mutable variable using a function with strict application.