ST is a monadic abstraction for local, in-place mutation. It uses a state token of type S to authorize operations on mutable data tagged with the same scope, while preventing mutable references from escaping that scope. section 14.2.1
Unlike State[S, A], which passes an immutable-looking state value from one action to the next, ST represents mutation through a token. Its underlying state-manipulating function remains unavailable for direct invocation outside the permitted scope. section 14.2.1
The abstraction provides:
- STRef for allocating, reading, and writing a mutable cell. section 14.5
- STArray for local mutable-array access and updates. section 14.5
Quicksort with local mutation
A functional quicksort can use STArray for the array and STRef for the partition index. Reads, swaps, and writes become composed ST actions, while the mutation remains unobservable outside the operation. section 14.2.1
