Control.Monad.ST.Lazy.Safe (original) (raw)

Contents

Description

Deprecated: Safe is now the default, please use Control.Monad.ST.Lazy instead

This module presents an identical interface to Control.Monad.ST, except that the monad delays evaluation of state operations until a value depending on them is required.

Safe API only.

Synopsis

The [ST](Control-Monad-ST-Lazy-Safe.html#t:ST "Control.Monad.ST.Lazy.Safe") monad

data ST s a Source #

The lazy state-transformer monad. A computation of type `[ST](Control-Monad-ST-Lazy-Safe.html#t:ST "Control.Monad.ST.Lazy.Safe")` s a transforms an internal state indexed by s, and returns a value of type a. The s parameter is either

It serves to keep the internal states of different invocations of[runST](Control-Monad-ST-Lazy-Safe.html#v:runST "Control.Monad.ST.Lazy.Safe") separate from each other and from invocations of [stToIO](Control-Monad-ST-Lazy-Safe.html#v:stToIO "Control.Monad.ST.Lazy.Safe").

The [>>=](Control-Monad.html#v:-62--62--61- "Control.Monad") and [>>](Control-Monad.html#v:-62--62- "Control.Monad") operations are not strict in the state. For example,

[runST](Control-Monad-ST-Lazy-Safe.html#v:runST "Control.Monad.ST.Lazy.Safe") (writeSTRef | v >>= readSTRef | >> return 2) = 2

runST :: (forall s. ST s a) -> a Source #

Return the value computed by a state transformer computation. The forall ensures that the internal state used by the [ST](Control-Monad-ST-Lazy-Safe.html#t:ST "Control.Monad.ST.Lazy.Safe") computation is inaccessible to the rest of the program.

fixST :: (a -> ST s a) -> ST s a Source #

Allow the result of a state transformer computation to be used (lazily) inside the computation. Note that if f is strict, `[fixST](Control-Monad-ST-Lazy-Safe.html#v:fixST "Control.Monad.ST.Lazy.Safe")` f = _|_.

Converting between strict and lazy [ST](Control-Monad-ST-Lazy-Safe.html#t:ST "Control.Monad.ST.Lazy.Safe")

strictToLazyST :: ST s a -> ST s a Source #

Convert a strict [ST](Control-Monad-ST-Lazy-Safe.html#t:ST "Control.Monad.ST.Lazy.Safe") computation into a lazy one. The strict state thread passed to [strictToLazyST](Control-Monad-ST-Lazy-Safe.html#v:strictToLazyST "Control.Monad.ST.Lazy.Safe") is not performed until the result of the lazy state thread it returns is demanded.

Converting [ST](Control-Monad-ST-Lazy-Safe.html#t:ST "Control.Monad.ST.Lazy.Safe") To [IO](System-IO.html#t:IO "System.IO")

data RealWorld :: Type #

RealWorld is deeply magical. It is primitive, but it is not_unlifted_ (hence ptrArg). We never manipulate values of typeRealWorld; it's only used in the type system, to parameterise State#.

stToIO :: ST RealWorld a -> IO a Source #

A monad transformer embedding lazy state transformers in the [IO](System-IO.html#t:IO "System.IO") monad. The [RealWorld](Control-Monad-ST-Lazy-Safe.html#t:RealWorld "Control.Monad.ST.Lazy.Safe") parameter indicates that the internal state used by the [ST](Control-Monad-ST-Lazy-Safe.html#t:ST "Control.Monad.ST.Lazy.Safe") computation is a special one supplied by the [IO](System-IO.html#t:IO "System.IO") monad, and thus distinct from those used by invocations of [runST](Control-Monad-ST-Lazy-Safe.html#v:runST "Control.Monad.ST.Lazy.Safe").