|Maintainer||Reiner Pope <email@example.com>|
An indexed version of the ST monad with support for safely freezing multiple arrays. Compare to the usual ST monad, where the only support for safely freezing arrays is runSTUArray -- only one array may be frozen.
This version of the ST monad has two distinct stages of processing: the normal stage, and the freeze stage. Reading and writing are permitted in the normal stage; reading and freezing are permitted in the freeze stage. This policy ensures that no writes occur after the arrays have been frozen.
This ST is an indexed monad (see Control.Monad.Indexed) as well
as a normal monad. That is, each monadic value will have an
"ingoing" state thread as well as an "outgoing" state
thread. These state threads are similar to the ST monad's state
thread, except that they are now annotated with a stage name:
- data Normal s
- data Freeze s
- class IxMonad st => MonadST st where
- type STNormal st s a = st (Normal s) (Normal s) a
- type STFreeze st s a = forall stg. st (stg s) (Freeze s) a
- type STRead st s a = forall stg. st (stg s) (stg s) a
- type ST = STT Identity
- runST :: (forall s. STT Identity (stg1 s) (stg2 s) a) -> a
- data STT m s t a
- class STTBase m where
For lifting any operations containing writes but no freezes.
For lifting any operations containing reads but no writes or freezes.
For lifting an
A computation containing some writes but no freezes: it starts
| and ends in the
A computation containing some freezes but no writes: it starts in | any stage, but ends in the Freeze stage.
A computation containing only reads: it starts and ends in any stage, but does not change stage. (Note that there would be no loss of safety in allowing the stage to change, but it may result in ambiguous types, or extra type annotations being required.)
An ST monad transformer. However, this is not a genuine monad
transformer, as that would be unsafe (see
retain safety, it may only act as a monad transformer over the
IO monads, enforced by the