Safe Haskell | None |
---|---|
Language | Haskell2010 |
Documentation
class AsLens s a ref where Source #
Convert a reference type to a Lens'
.
Instances
AsLens (S 'OpST RealWorld) a IORef Source # | |
AsLens (S 'OpMVar RealWorld) a MVar Source # | View a Note: when this is eventually run in If you don't want to deal with this, don't use an |
AsLens (S 'OpSTM RealWorld) a TMVar Source # | |
AsLens (S 'OpSTM RealWorld) a TVar Source # | |
AsLens (S 'OpST s) a (STRef s) Source # | |
AsLens (S 'OpST s) a (MutVar s) Source # | |
class AsLens s a ref => Allocable s a ref where Source #
A state in which you can allocate new references.
This can be defined on either pure or impure references. For pure references
one could e.g. define an instance of this on Map k v
with Const k
as the
reference type - see unit tests for an example.
alloc :: a -> s -> (ref a, s) Source #
Allocate a new reference with the given value.
free :: HasCallStack => ref a -> s -> (a, s) Source #
Deallocate an existing reference, and return its value.
The default implementation simply writes error
into the reference and
returns the old value. The caller is responsible for actually throwing away
the reference and never using it again, as per Haskell's GC semantics.
isValid :: ref a -> s -> (Bool, s) Source #
Check if a reference is valid.
The default implementation simply forces the reference and returns True
. If
the reference has already been freed (via free
) then an error will be
raised, which you can catch in the IO
monad as per usual. In other words,
the default implementation will never return False
.