TRefType

Represents a transactional reference that can be updated atomically within an STM`1 transaction.

Specification

Kind
Type
Members
4
Examples
0
makeSignature
TRef.make value
getSignature
TRef.get tref
setSignature
TRef.set value tref
updateSignature
TRef.update f tref

Summary

NameSignatureSynopsis
Operations
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.

Operations

kind:member

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
}
kind:member

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
}
kind:member

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
}
kind:member

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
}