TRefModule
PackageAxial
Summary
| Name | Signature | Synopsis |
|---|---|---|
| make | TRef.make value | Creates a new 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. |
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
}Reads the current value of the transactional reference within a transaction.
Parameters
| Name | Type | Description |
|---|---|---|
| tref | TRef<'T> | The transactional reference to read. |
Returns
STM<'T>
Verification Examples
let tx (counter: TRef<int>) = stm {
let! value = TRef.get counter
return value
}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
}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
}
