TRefType
TRef
TRef<'T> is a transactional reference: a variable read and written inside an STM transaction. Read the
STM guide for retry and orElse behavior.
Signature reference
| Function | Signature | Description |
|---|---|---|
make |
'T -> STM<TRef<'T>> |
Creates a new transactional reference. |
get |
TRef<'T> -> STM<'T> |
Reads the value of a TRef within a transaction. |
set |
'T -> TRef<'T> -> STM<unit> |
Sets the value of a TRef within a transaction. |
update |
('T -> 'T) -> TRef<'T> -> STM<unit> |
Atomically updates a TRef within a transaction. |
Specification
Kind
Type
Members
8
Examples
0
makeSignature
TRef.make value
getSignature
TRef.get tref
setSignature
TRef.set value tref
updateSignature
TRef.update f tref
modifySignature
TRef.modify f tref
Summary
| Name | Signature | Synopsis |
|---|---|---|
| Operations | ||
| make | TRef.make value | Creates a new TRef with the initial value within an STM transaction. |
| get | TRef.get tref | Reads the current value of the transactional reference within a transaction. |
| set | TRef.set value tref | Sets the value of the transactional reference within a transaction. |
| update | TRef.update f tref | Updates the value of the transactional reference within a transaction using the supplied function. |
| modify | TRef.modify f tref | Atomically applies f, writes the new state, and returns the value it produced. |
| getAndSet | TRef.getAndSet value tref | Sets the value and returns the previous value. |
| getAndUpdate | TRef.getAndUpdate f tref | Updates the value and returns the previous value. |
| updateAndGet | TRef.updateAndGet f tref | Updates the value and returns the new value. |
Operations
kind:member
Creates a new TRef`1 with the initial value within an STM transaction.
Parameters
| Name | Type | Description |
|---|---|---|
| value | 'T | The initial value for the transactional reference. |
Returns
STM<TRef<'T>>
Verification Examples
let tx = stm {
let! counter = TRef.make 0
return counter
}kind:member
kind:member
Sets the value of the transactional reference within a transaction.
Parameters
| Name | Type | Description |
|---|---|---|
| value | 'T | The new value to store in the reference. |
| tref | TRef<'T> | The transactional reference to update. |
Returns
STM<unit>
Verification Examples
let tx (counter: TRef<int>) = stm {
do! TRef.set 10 counter
}kind:member
Updates the value of the transactional reference within a transaction using the supplied function.
Parameters
| Name | Type | Description |
|---|---|---|
| f | 'T -> 'T | The function to apply to the current value to produce the new value. |
| tref | TRef<'T> | The transactional reference to update. |
Returns
STM<unit>
Verification Examples
let tx (counter: TRef<int>) = stm {
do! TRef.update (fun n -> n + 1) counter
}kind:member
kind:member
kind:member

