TRefModule

PackageAxial

Summary

NameSignatureSynopsis
makeTRef.make valueCreates a new with the initial value within an STM transaction.
getTRef.get trefReads the current value of the transactional reference within a transaction.
setTRef.set value trefSets the value of the transactional reference within a transaction.
updateTRef.update f trefUpdates the value of the transactional reference within a transaction using the supplied function.

make

TRef.make value
Member
Creates a new TRef`1 with the initial value within an STM transaction.

Parameters

NameTypeDescription
value'TThe initial value for the transactional reference.

Returns

STM<TRef<'T>>

Verification Examples

let tx = stm {
    let! counter = TRef.make 0
    return counter
}

get

TRef.get tref
Member
Reads the current value of the transactional reference within a transaction.

Parameters

NameTypeDescription
trefTRef<'T>The transactional reference to read.

Returns

STM<'T>

Verification Examples

let tx (counter: TRef<int>) = stm {
    let! value = TRef.get counter
    return value
}

set

TRef.set value tref
Member
Sets the value of the transactional reference within a transaction.

Parameters

NameTypeDescription
value'TThe new value to store in the reference.
trefTRef<'T>The transactional reference to update.

Returns

STM<unit>

Verification Examples

let tx (counter: TRef<int>) = stm {
    do! TRef.set 10 counter
}

update

TRef.update f tref
Member
Updates the value of the transactional reference within a transaction using the supplied function.

Parameters

NameTypeDescription
f'T -> 'TThe function to apply to the current value to produce the new value.
trefTRef<'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
}