regions-0.4: Provides the region monad for safely opening and working with scarce resources.Source codeContentsIndex
Data.RegionRef
MaintainerBas van Dijk <v.dijk.bas@gmail.com>
Description
A mutable variable in the region monad that should provide a safer replacement for an IORef because you can't use it outside the region in which it was created (unless you explicitly duplicate it).
Synopsis
data RegionRef r α
pureDup :: RegionRef (RegionT cs (RegionT ps ppr)) α -> RegionRef (RegionT ps ppr) α
newRegionRef :: MonadIO pr => α -> RegionT s pr (RegionRef (RegionT s pr) α)
readRegionRef :: (ParentOf pr cr, MonadIO cr) => RegionRef pr α -> cr α
writeRegionRef :: (ParentOf pr cr, MonadIO cr) => RegionRef pr α -> α -> cr ()
modifyRegionRef :: (ParentOf pr cr, MonadIO cr) => RegionRef pr α -> (α -> α) -> cr ()
atomicModifyRegionRef :: (ParentOf pr cr, MonadIO cr) => RegionRef pr α -> (α -> (α, β)) -> cr β
Documentation
data RegionRef r α Source
A mutable variable storing a value of type α which can only be used in region r, r's children or r's parent when you duplicate it using pureDup.
show/hide Instances
Eq (RegionRef r α)
pureDup :: RegionRef (RegionT cs (RegionT ps ppr)) α -> RegionRef (RegionT ps ppr) αSource
Transform the region type r of the regional reference to r's parent so that it can be used in that region.
newRegionRef :: MonadIO pr => α -> RegionT s pr (RegionRef (RegionT s pr) α)Source

Yield a regional computation that returns a new regional reference that stores the given value.

Note that the reference is parameterized by the same region in which it was created. This ensures you can never use this reference outside that region and it allows you to use this reference in a child region of that region

readRegionRef :: (ParentOf pr cr, MonadIO cr) => RegionRef pr α -> cr αSource
Read the value of the given regional reference.
writeRegionRef :: (ParentOf pr cr, MonadIO cr) => RegionRef pr α -> α -> cr ()Source
Write a new value into the given regional reference.
modifyRegionRef :: (ParentOf pr cr, MonadIO cr) => RegionRef pr α -> (α -> α) -> cr ()Source
Mutate the contents of the given regional reference using the given function.
atomicModifyRegionRef :: (ParentOf pr cr, MonadIO cr) => RegionRef pr α -> (α -> (α, β)) -> cr βSource

Atomically modifies the contents of the given regional reference using the given function.

This function is useful for using a regional reference in a safe way in a multithreaded program. If you only have one regional reference, then using atomicModifyRegionRef to access and modify it will prevent race conditions.

Produced by Haddock version 2.6.0