<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <!--Rendered using the Haskell Html Library v0.2--> <HTML ><HEAD ><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8" ><TITLE >Control.Monad.ST.Lazy</TITLE ><LINK HREF="haddock.css" REL="stylesheet" TYPE="text/css" ><SCRIPT SRC="haddock-util.js" TYPE="text/javascript" ></SCRIPT ><SCRIPT TYPE="text/javascript" >window.onload = function () {setSynopsis("mini_Control-Monad-ST-Lazy.html")};</SCRIPT ></HEAD ><BODY ><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0" ><TR ><TD CLASS="topbar" ><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0" ><TR ><TD ><IMG SRC="haskell_icon.gif" WIDTH="16" HEIGHT="16" ALT=" " ></TD ><TD CLASS="title" >base-4.1.0.0: Basic libraries</TD ><TD CLASS="topbut" ><A HREF="index.html" >Contents</A ></TD ><TD CLASS="topbut" ><A HREF="doc-index.html" >Index</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="modulebar" ><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0" ><TR ><TD ><FONT SIZE="6" >Control.Monad.ST.Lazy</FONT ></TD ><TD ALIGN="right" ><TABLE CLASS="narrow" CELLSPACING="0" CELLPADDING="0" ><TR ><TD CLASS="infohead" >Portability</TD ><TD CLASS="infoval" >non-portable (requires universal quantification for runST)</TD ></TR ><TR ><TD CLASS="infohead" >Stability</TD ><TD CLASS="infoval" >provisional</TD ></TR ><TR ><TD CLASS="infohead" >Maintainer</TD ><TD CLASS="infoval" >libraries@haskell.org</TD ></TR ></TABLE ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD ><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0" ><TR ><TD CLASS="section4" ><B >Contents</B ></TD ></TR ><TR ><TD ><DL ><DT ><A HREF="#1" >The <TT ><A HREF="Control-Monad-ST-Lazy.html#t%3AST" >ST</A ></TT > monad </A ></DT ><DT ><A HREF="#2" >Converting between strict and lazy <TT ><A HREF="Control-Monad-ST-Lazy.html#t%3AST" >ST</A ></TT > </A ></DT ><DT ><A HREF="#3" >Converting <TT ><A HREF="Control-Monad-ST-Lazy.html#t%3AST" >ST</A ></TT > To <TT ><A HREF="System-IO.html#t%3AIO" >IO</A ></TT > </A ></DT ><DT ><A HREF="#4" >Unsafe operations </A ></DT ></DL ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="section1" >Description</TD ></TR ><TR ><TD CLASS="doc" >This module presents an identical interface to <A HREF="Control-Monad-ST.html" >Control.Monad.ST</A >, except that the monad delays evaluation of state operations until a value depending on them is required. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="section1" >Synopsis</TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="body" ><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0" ><TR ><TD CLASS="decl" ><SPAN CLASS="keyword" >data</SPAN > <A HREF="#t%3AST" >ST</A > s a</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3ArunST" >runST</A > :: (<SPAN CLASS="keyword" >forall</SPAN > s. <A HREF="Control-Monad-ST-Lazy.html#t%3AST" >ST</A > s a) -> a</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3AfixST" >fixST</A > :: (a -> <A HREF="Control-Monad-ST-Lazy.html#t%3AST" >ST</A > s a) -> <A HREF="Control-Monad-ST-Lazy.html#t%3AST" >ST</A > s a</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3AstrictToLazyST" >strictToLazyST</A > :: <A HREF="Control-Monad-ST.html#t%3AST" >ST</A > s a -> <A HREF="Control-Monad-ST-Lazy.html#t%3AST" >ST</A > s a</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3AlazyToStrictST" >lazyToStrictST</A > :: <A HREF="Control-Monad-ST-Lazy.html#t%3AST" >ST</A > s a -> <A HREF="Control-Monad-ST.html#t%3AST" >ST</A > s a</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="../ghc-prim/GHC-Prim.html#t%3ARealWorld" >RealWorld</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3AstToIO" >stToIO</A > :: <A HREF="Control-Monad-ST-Lazy.html#t%3AST" >ST</A > <A HREF="../ghc-prim/GHC-Prim.html#t%3ARealWorld" >RealWorld</A > a -> <A HREF="System-IO.html#t%3AIO" >IO</A > a</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3AunsafeInterleaveST" >unsafeInterleaveST</A > :: <A HREF="Control-Monad-ST-Lazy.html#t%3AST" >ST</A > s a -> <A HREF="Control-Monad-ST-Lazy.html#t%3AST" >ST</A > s a</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3AunsafeIOToST" >unsafeIOToST</A > :: <A HREF="System-IO.html#t%3AIO" >IO</A > a -> <A HREF="Control-Monad-ST-Lazy.html#t%3AST" >ST</A > s a</TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="section1" ><A NAME="1" ><A NAME="1" >The <TT ><A HREF="Control-Monad-ST-Lazy.html#t%3AST" >ST</A ></TT > monad </A ></A ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><SPAN CLASS="keyword" >data</SPAN > <A NAME="t:ST" ><A NAME="t%3AST" ></A ></A ><B >ST</B > s a </TD ></TR ><TR ><TD CLASS="body" ><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0" ><TR ><TD CLASS="ndoc" ><P >The lazy state-transformer monad. A computation of type <TT ><TT ><A HREF="Control-Monad-ST-Lazy.html#t%3AST" >ST</A ></TT > s a</TT > transforms an internal state indexed by <TT >s</TT >, and returns a value of type <TT >a</TT >. The <TT >s</TT > parameter is either </P ><UL ><LI > an unstantiated type variable (inside invocations of <TT ><A HREF="Control-Monad-ST-Lazy.html#v%3ArunST" >runST</A ></TT >), or </LI ><LI > <TT ><A HREF="../ghc-prim/GHC-Prim.html#t%3ARealWorld" >RealWorld</A ></TT > (inside invocations of <TT ><A HREF="Control-Monad-ST-Lazy.html#v%3AstToIO" >stToIO</A ></TT >). </LI ></UL ><P >It serves to keep the internal states of different invocations of <TT ><A HREF="Control-Monad-ST-Lazy.html#v%3ArunST" >runST</A ></TT > separate from each other and from invocations of <TT ><A HREF="Control-Monad-ST-Lazy.html#v%3AstToIO" >stToIO</A ></TT >. </P ><P >The <TT ><A HREF="Control-Monad.html#v%3A%3E%3E%3D" >>>=</A ></TT > and <TT ><A HREF="Control-Monad.html#v%3A%3E%3E" >>></A ></TT > operations are not strict in the state. For example, </P ><PRE ><TT ><A HREF="Control-Monad-ST-Lazy.html#v%3ArunST" >runST</A ></TT > (writeSTRef _|_ v >>= readSTRef _|_ >> return 2) = 2</PRE ></TD ></TR ><TR ><TD CLASS="section4" ><IMG SRC="minus.gif" CLASS="coll" ONCLICK="toggle(this,'i:ST')" ALT="show/hide" > Instances</TD ></TR ><TR ><TD CLASS="body" ><DIV ID="i:ST" STYLE="display:block;" ><TABLE CLASS="vanilla" CELLSPACING="1" CELLPADDING="0" ><TR ><TD CLASS="decl" ><A HREF="Control-Monad.html#t%3AMonad" >Monad</A > (<A HREF="Control-Monad-ST-Lazy.html#t%3AST" >ST</A > s)</TD ></TR ><TR ><TD CLASS="decl" ><A HREF="Control-Monad.html#t%3AFunctor" >Functor</A > (<A HREF="Control-Monad-ST-Lazy.html#t%3AST" >ST</A > s)</TD ></TR ><TR ><TD CLASS="decl" ><A HREF="Control-Monad-Fix.html#t%3AMonadFix" >MonadFix</A > (<A HREF="Control-Monad-ST-Lazy.html#t%3AST" >ST</A > s)</TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:runST" ><A NAME="v%3ArunST" ></A ></A ><B >runST</B > :: (<SPAN CLASS="keyword" >forall</SPAN > s. <A HREF="Control-Monad-ST-Lazy.html#t%3AST" >ST</A > s a) -> a</TD ></TR ><TR ><TD CLASS="doc" >Return the value computed by a state transformer computation. The <TT >forall</TT > ensures that the internal state used by the <TT ><A HREF="Control-Monad-ST-Lazy.html#t%3AST" >ST</A ></TT > computation is inaccessible to the rest of the program. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:fixST" ><A NAME="v%3AfixST" ></A ></A ><B >fixST</B > :: (a -> <A HREF="Control-Monad-ST-Lazy.html#t%3AST" >ST</A > s a) -> <A HREF="Control-Monad-ST-Lazy.html#t%3AST" >ST</A > s a</TD ></TR ><TR ><TD CLASS="doc" >Allow the result of a state transformer computation to be used (lazily) inside the computation. Note that if <TT >f</TT > is strict, <TT ><TT ><A HREF="Control-Monad-ST-Lazy.html#v%3AfixST" >fixST</A ></TT > f = _|_</TT >. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="section1" ><A NAME="2" ><A NAME="2" >Converting between strict and lazy <TT ><A HREF="Control-Monad-ST-Lazy.html#t%3AST" >ST</A ></TT > </A ></A ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:strictToLazyST" ><A NAME="v%3AstrictToLazyST" ></A ></A ><B >strictToLazyST</B > :: <A HREF="Control-Monad-ST.html#t%3AST" >ST</A > s a -> <A HREF="Control-Monad-ST-Lazy.html#t%3AST" >ST</A > s a</TD ></TR ><TR ><TD CLASS="doc" >Convert a strict <TT ><A HREF="Control-Monad-ST-Lazy.html#t%3AST" >ST</A ></TT > computation into a lazy one. The strict state thread passed to <TT ><A HREF="Control-Monad-ST-Lazy.html#v%3AstrictToLazyST" >strictToLazyST</A ></TT > is not performed until the result of the lazy state thread it returns is demanded. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:lazyToStrictST" ><A NAME="v%3AlazyToStrictST" ></A ></A ><B >lazyToStrictST</B > :: <A HREF="Control-Monad-ST-Lazy.html#t%3AST" >ST</A > s a -> <A HREF="Control-Monad-ST.html#t%3AST" >ST</A > s a</TD ></TR ><TR ><TD CLASS="doc" >Convert a lazy <TT ><A HREF="Control-Monad-ST-Lazy.html#t%3AST" >ST</A ></TT > computation into a strict one. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="section1" ><A NAME="3" ><A NAME="3" >Converting <TT ><A HREF="Control-Monad-ST-Lazy.html#t%3AST" >ST</A ></TT > To <TT ><A HREF="System-IO.html#t%3AIO" >IO</A ></TT > </A ></A ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="../ghc-prim/GHC-Prim.html#t%3ARealWorld" >RealWorld</A ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:stToIO" ><A NAME="v%3AstToIO" ></A ></A ><B >stToIO</B > :: <A HREF="Control-Monad-ST-Lazy.html#t%3AST" >ST</A > <A HREF="../ghc-prim/GHC-Prim.html#t%3ARealWorld" >RealWorld</A > a -> <A HREF="System-IO.html#t%3AIO" >IO</A > a</TD ></TR ><TR ><TD CLASS="doc" >A monad transformer embedding lazy state transformers in the <TT ><A HREF="System-IO.html#t%3AIO" >IO</A ></TT > monad. The <TT ><A HREF="../ghc-prim/GHC-Prim.html#t%3ARealWorld" >RealWorld</A ></TT > parameter indicates that the internal state used by the <TT ><A HREF="Control-Monad-ST-Lazy.html#t%3AST" >ST</A ></TT > computation is a special one supplied by the <TT ><A HREF="System-IO.html#t%3AIO" >IO</A ></TT > monad, and thus distinct from those used by invocations of <TT ><A HREF="Control-Monad-ST-Lazy.html#v%3ArunST" >runST</A ></TT >. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="section1" ><A NAME="4" ><A NAME="4" >Unsafe operations </A ></A ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:unsafeInterleaveST" ><A NAME="v%3AunsafeInterleaveST" ></A ></A ><B >unsafeInterleaveST</B > :: <A HREF="Control-Monad-ST-Lazy.html#t%3AST" >ST</A > s a -> <A HREF="Control-Monad-ST-Lazy.html#t%3AST" >ST</A > s a</TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="decl" ><A NAME="v:unsafeIOToST" ><A NAME="v%3AunsafeIOToST" ></A ></A ><B >unsafeIOToST</B > :: <A HREF="System-IO.html#t%3AIO" >IO</A > a -> <A HREF="Control-Monad-ST-Lazy.html#t%3AST" >ST</A > s a</TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="botbar" >Produced by <A HREF="http://www.haskell.org/haddock/" >Haddock</A > version 2.4.2</TD ></TR ></TABLE ></BODY ></HTML >