/usr/share/doc/libghc-monads-tf-doc/html/Control-Monad-State-Strict.html is in libghc-monads-tf-doc 0.1.0.3-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Control.Monad.State.Strict</title><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean" /><script src="haddock-util.js" type="text/javascript"></script><script src="file:///usr/share/javascript/mathjax/MathJax.js" type="text/javascript"></script><script type="text/javascript">//<![CDATA[
window.onload = function () {pageLoad();setSynopsis("mini_Control-Monad-State-Strict.html");};
//]]>
</script></head><body><div id="package-header"><ul class="links" id="page-menu"><li><a href="src/Control-Monad-State-Strict.html">Source</a></li><li><a href="index.html">Contents</a></li><li><a href="doc-index.html">Index</a></li></ul><p class="caption">monads-tf-0.1.0.3: Monad classes, using type families</p></div><div id="content"><div id="module-header"><table class="info"><tr><th>Copyright</th><td>(c) Andy Gill 2001,
(c) Oregon Graduate Institute of Science and Technology, 2001</td></tr><tr><th>License</th><td>BSD-style (see the file LICENSE)</td></tr><tr><th>Maintainer</th><td>ross@soi.city.ac.uk</td></tr><tr><th>Stability</th><td>experimental</td></tr><tr><th>Portability</th><td>non-portable (type families)</td></tr><tr><th>Safe Haskell</th><td>Safe</td></tr><tr><th>Language</th><td>Haskell98</td></tr></table><p class="caption">Control.Monad.State.Strict</p></div><div id="table-of-contents"><p class="caption">Contents</p><ul><li><a href="#g:1">MonadState class</a></li><li><a href="#g:2">The State monad</a></li><li><a href="#g:3">The StateT monad transformer</a></li><li><a href="#g:4">Examples</a></li></ul></div><div id="description"><p class="caption">Description</p><div class="doc"><p>Strict state monads.</p><p>This module is inspired by the paper
/Functional Programming with Overloading and
Higher-Order Polymorphism/,
Mark P Jones (<a href="http://web.cecs.pdx.edu/~mpj/">http://web.cecs.pdx.edu/~mpj/</a>)
Advanced School of Functional Programming, 1995.</p></div></div><div id="synopsis"><p id="control.syn" class="caption expander" onclick="toggleSection('syn')">Synopsis</p><ul id="section.syn" class="hide" onclick="toggleSection('syn')"><li class="src short"><span class="keyword">class</span> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Control-Monad.html#t:Monad">Monad</a> m => <a href="#t:MonadState">MonadState</a> m <span class="keyword">where</span><ul class="subs"><li><span class="keyword">type</span> <a href="#t:StateType">StateType</a> m</li></ul></li><li class="src short"><a href="#v:modify">modify</a> :: <a href="Control-Monad-State-Strict.html#t:MonadState">MonadState</a> m => (<a href="Control-Monad-State-Strict.html#t:StateType">StateType</a> m -> <a href="Control-Monad-State-Strict.html#t:StateType">StateType</a> m) -> m ()</li><li class="src short"><a href="#v:gets">gets</a> :: <a href="Control-Monad-State-Strict.html#t:MonadState">MonadState</a> m => (<a href="Control-Monad-State-Strict.html#t:StateType">StateType</a> m -> a) -> m a</li><li class="src short"><span class="keyword">type</span> <a href="#t:State">State</a> s = <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Functor-Identity.html#t:Identity">Identity</a></li><li class="src short"><a href="#v:runState">runState</a> :: <a href="Control-Monad-State-Strict.html#t:State">State</a> s a -> s -> (a, s)</li><li class="src short"><a href="#v:evalState">evalState</a> :: <a href="Control-Monad-State-Strict.html#t:State">State</a> s a -> s -> a</li><li class="src short"><a href="#v:execState">execState</a> :: <a href="Control-Monad-State-Strict.html#t:State">State</a> s a -> s -> s</li><li class="src short"><a href="#v:mapState">mapState</a> :: ((a, s) -> (b, s)) -> <a href="Control-Monad-State-Strict.html#t:State">State</a> s a -> <a href="Control-Monad-State-Strict.html#t:State">State</a> s b</li><li class="src short"><a href="#v:withState">withState</a> :: (s -> s) -> <a href="Control-Monad-State-Strict.html#t:State">State</a> s a -> <a href="Control-Monad-State-Strict.html#t:State">State</a> s a</li><li class="src short"><span class="keyword">newtype</span> <a href="#t:StateT">StateT</a> s m a :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> -> (<a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> -> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a>) -> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> -> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> = <a href="#v:StateT">StateT</a> {<ul class="subs"><li><a href="#v:runStateT">runStateT</a> :: s -> m (a, s)</li></ul>}</li><li class="src short"><a href="#v:evalStateT">evalStateT</a> :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Control-Monad.html#t:Monad">Monad</a> m => <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m a -> s -> m a</li><li class="src short"><a href="#v:execStateT">execStateT</a> :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Control-Monad.html#t:Monad">Monad</a> m => <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m a -> s -> m s</li><li class="src short"><a href="#v:mapStateT">mapStateT</a> :: (m (a, s) -> n (b, s)) -> <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m a -> <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s n b</li><li class="src short"><a href="#v:withStateT">withStateT</a> :: (s -> s) -> <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m a -> <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m a</li><li class="src short">module <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Control-Monad.html">Control.Monad</a></li><li class="src short">module <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Control-Monad-Fix.html">Control.Monad.Fix</a></li><li class="src short">module <a href="Control-Monad-Trans.html">Control.Monad.Trans</a></li></ul></div><div id="interface"><h1 id="g:1">MonadState class</h1><div class="top"><p class="src"><span class="keyword">class</span> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Control-Monad.html#t:Monad">Monad</a> m => <a id="t:MonadState" class="def">MonadState</a> m <span class="keyword">where</span> <a href="src/Control-Monad-State-Class.html#MonadState" class="link">Source</a> <a href="#t:MonadState" class="selflink">#</a></p><div class="doc"><p><em>get</em> returns the state from the internals of the monad.</p><p><em>put</em> replaces the state inside the monad.</p></div><div class="subs minimal"><p class="caption">Minimal complete definition</p><p class="src"><a href="Control-Monad-State-Strict.html#v:get">get</a>, <a href="Control-Monad-State-Strict.html#v:put">put</a></p></div><div class="subs associated-types"><p class="caption">Associated Types</p><p class="src"><span class="keyword">type</span> <a id="t:StateType" class="def">StateType</a> m <a href="src/Control-Monad-State-Class.html#StateType" class="link">Source</a> <a href="#t:StateType" class="selflink">#</a></p></div><div class="subs methods"><p class="caption">Methods</p><p class="src"><a id="v:get" class="def">get</a> :: m (<a href="Control-Monad-State-Strict.html#t:StateType">StateType</a> m) <a href="src/Control-Monad-State-Class.html#get" class="link">Source</a> <a href="#v:get" class="selflink">#</a></p><p class="src"><a id="v:put" class="def">put</a> :: <a href="Control-Monad-State-Strict.html#t:StateType">StateType</a> m -> m () <a href="src/Control-Monad-State-Class.html#put" class="link">Source</a> <a href="#v:put" class="selflink">#</a></p></div><div class="subs instances"><p id="control.i:MonadState" class="caption collapser" onclick="toggleSection('i:MonadState')">Instances</p><div id="section.i:MonadState" class="show"><table><tr><td class="src clearfix"><span class="inst-left"><span id="control.i:ic:MonadState:MonadState:1" class="instance expander" onclick="toggleSection('i:ic:MonadState:MonadState:1')"></span> <a href="Control-Monad-State-Strict.html#t:MonadState">MonadState</a> m => <a href="Control-Monad-State-Strict.html#t:MonadState">MonadState</a> (<a href="file:///usr/share/doc/ghc-doc/html/libraries/transformers-0.5.2.0/Control-Monad-Trans-Maybe.html#t:MaybeT">MaybeT</a> m)</span> <a href="src/Control-Monad-State-Class.html#line-122" class="link">Source</a> <a href="#t:MonadState" class="selflink">#</a></td><td class="doc empty"> </td></tr><tr><td colspan="2"><div id="section.i:ic:MonadState:MonadState:1" class="inst-details hide"><div class="subs associated-types"><p class="caption">Associated Types</p><p class="src"><span class="keyword">type</span> <a href="Control-Monad-State-Strict.html#t:StateType">StateType</a> (<a href="file:///usr/share/doc/ghc-doc/html/libraries/transformers-0.5.2.0/Control-Monad-Trans-Maybe.html#t:MaybeT">MaybeT</a> m :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> -> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a>) :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> <a href="src/Control-Monad-State-Class.html#StateType" class="link">Source</a> <a href="#t:StateType" class="selflink">#</a></p></div> <div class="subs methods"><p class="caption">Methods</p><p class="src"><a href="#v:get">get</a> :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/transformers-0.5.2.0/Control-Monad-Trans-Maybe.html#t:MaybeT">MaybeT</a> m (<a href="Control-Monad-State-Strict.html#t:StateType">StateType</a> (<a href="file:///usr/share/doc/ghc-doc/html/libraries/transformers-0.5.2.0/Control-Monad-Trans-Maybe.html#t:MaybeT">MaybeT</a> m)) <a href="src/Control-Monad-State-Class.html#get" class="link">Source</a> <a href="#v:get" class="selflink">#</a></p><p class="src"><a href="#v:put">put</a> :: <a href="Control-Monad-State-Strict.html#t:StateType">StateType</a> (<a href="file:///usr/share/doc/ghc-doc/html/libraries/transformers-0.5.2.0/Control-Monad-Trans-Maybe.html#t:MaybeT">MaybeT</a> m) -> <a href="file:///usr/share/doc/ghc-doc/html/libraries/transformers-0.5.2.0/Control-Monad-Trans-Maybe.html#t:MaybeT">MaybeT</a> m () <a href="src/Control-Monad-State-Class.html#put" class="link">Source</a> <a href="#v:put" class="selflink">#</a></p></div></div></td></tr><tr><td class="src clearfix"><span class="inst-left"><span id="control.i:ic:MonadState:MonadState:2" class="instance expander" onclick="toggleSection('i:ic:MonadState:MonadState:2')"></span> <a href="Control-Monad-State-Strict.html#t:MonadState">MonadState</a> m => <a href="Control-Monad-State-Strict.html#t:MonadState">MonadState</a> (<a href="Control-Monad-List.html#t:ListT">ListT</a> m)</span> <a href="src/Control-Monad-State-Class.html#line-117" class="link">Source</a> <a href="#t:MonadState" class="selflink">#</a></td><td class="doc empty"> </td></tr><tr><td colspan="2"><div id="section.i:ic:MonadState:MonadState:2" class="inst-details hide"><div class="subs associated-types"><p class="caption">Associated Types</p><p class="src"><span class="keyword">type</span> <a href="Control-Monad-State-Strict.html#t:StateType">StateType</a> (<a href="Control-Monad-List.html#t:ListT">ListT</a> m :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> -> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a>) :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> <a href="src/Control-Monad-State-Class.html#StateType" class="link">Source</a> <a href="#t:StateType" class="selflink">#</a></p></div> <div class="subs methods"><p class="caption">Methods</p><p class="src"><a href="#v:get">get</a> :: <a href="Control-Monad-List.html#t:ListT">ListT</a> m (<a href="Control-Monad-State-Strict.html#t:StateType">StateType</a> (<a href="Control-Monad-List.html#t:ListT">ListT</a> m)) <a href="src/Control-Monad-State-Class.html#get" class="link">Source</a> <a href="#v:get" class="selflink">#</a></p><p class="src"><a href="#v:put">put</a> :: <a href="Control-Monad-State-Strict.html#t:StateType">StateType</a> (<a href="Control-Monad-List.html#t:ListT">ListT</a> m) -> <a href="Control-Monad-List.html#t:ListT">ListT</a> m () <a href="src/Control-Monad-State-Class.html#put" class="link">Source</a> <a href="#v:put" class="selflink">#</a></p></div></div></td></tr><tr><td class="src clearfix"><span class="inst-left"><span id="control.i:ic:MonadState:MonadState:3" class="instance expander" onclick="toggleSection('i:ic:MonadState:MonadState:3')"></span> (<a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Monoid.html#t:Monoid">Monoid</a> w, <a href="Control-Monad-State-Strict.html#t:MonadState">MonadState</a> m) => <a href="Control-Monad-State-Strict.html#t:MonadState">MonadState</a> (<a href="Control-Monad-Writer-Strict.html#t:WriterT">WriterT</a> w m)</span> <a href="src/Control-Monad-State-Class.html#line-137" class="link">Source</a> <a href="#t:MonadState" class="selflink">#</a></td><td class="doc empty"> </td></tr><tr><td colspan="2"><div id="section.i:ic:MonadState:MonadState:3" class="inst-details hide"><div class="subs associated-types"><p class="caption">Associated Types</p><p class="src"><span class="keyword">type</span> <a href="Control-Monad-State-Strict.html#t:StateType">StateType</a> (<a href="Control-Monad-Writer-Strict.html#t:WriterT">WriterT</a> w m :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> -> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a>) :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> <a href="src/Control-Monad-State-Class.html#StateType" class="link">Source</a> <a href="#t:StateType" class="selflink">#</a></p></div> <div class="subs methods"><p class="caption">Methods</p><p class="src"><a href="#v:get">get</a> :: <a href="Control-Monad-Writer-Strict.html#t:WriterT">WriterT</a> w m (<a href="Control-Monad-State-Strict.html#t:StateType">StateType</a> (<a href="Control-Monad-Writer-Strict.html#t:WriterT">WriterT</a> w m)) <a href="src/Control-Monad-State-Class.html#get" class="link">Source</a> <a href="#v:get" class="selflink">#</a></p><p class="src"><a href="#v:put">put</a> :: <a href="Control-Monad-State-Strict.html#t:StateType">StateType</a> (<a href="Control-Monad-Writer-Strict.html#t:WriterT">WriterT</a> w m) -> <a href="Control-Monad-Writer-Strict.html#t:WriterT">WriterT</a> w m () <a href="src/Control-Monad-State-Class.html#put" class="link">Source</a> <a href="#v:put" class="selflink">#</a></p></div></div></td></tr><tr><td class="src clearfix"><span class="inst-left"><span id="control.i:ic:MonadState:MonadState:4" class="instance expander" onclick="toggleSection('i:ic:MonadState:MonadState:4')"></span> (<a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Monoid.html#t:Monoid">Monoid</a> w, <a href="Control-Monad-State-Strict.html#t:MonadState">MonadState</a> m) => <a href="Control-Monad-State-Strict.html#t:MonadState">MonadState</a> (<a href="Control-Monad-Writer-Lazy.html#t:WriterT">WriterT</a> w m)</span> <a href="src/Control-Monad-State-Class.html#line-132" class="link">Source</a> <a href="#t:MonadState" class="selflink">#</a></td><td class="doc empty"> </td></tr><tr><td colspan="2"><div id="section.i:ic:MonadState:MonadState:4" class="inst-details hide"><div class="subs associated-types"><p class="caption">Associated Types</p><p class="src"><span class="keyword">type</span> <a href="Control-Monad-State-Strict.html#t:StateType">StateType</a> (<a href="Control-Monad-Writer-Lazy.html#t:WriterT">WriterT</a> w m :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> -> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a>) :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> <a href="src/Control-Monad-State-Class.html#StateType" class="link">Source</a> <a href="#t:StateType" class="selflink">#</a></p></div> <div class="subs methods"><p class="caption">Methods</p><p class="src"><a href="#v:get">get</a> :: <a href="Control-Monad-Writer-Lazy.html#t:WriterT">WriterT</a> w m (<a href="Control-Monad-State-Strict.html#t:StateType">StateType</a> (<a href="Control-Monad-Writer-Lazy.html#t:WriterT">WriterT</a> w m)) <a href="src/Control-Monad-State-Class.html#get" class="link">Source</a> <a href="#v:get" class="selflink">#</a></p><p class="src"><a href="#v:put">put</a> :: <a href="Control-Monad-State-Strict.html#t:StateType">StateType</a> (<a href="Control-Monad-Writer-Lazy.html#t:WriterT">WriterT</a> w m) -> <a href="Control-Monad-Writer-Lazy.html#t:WriterT">WriterT</a> w m () <a href="src/Control-Monad-State-Class.html#put" class="link">Source</a> <a href="#v:put" class="selflink">#</a></p></div></div></td></tr><tr><td class="src clearfix"><span class="inst-left"><span id="control.i:ic:MonadState:MonadState:5" class="instance expander" onclick="toggleSection('i:ic:MonadState:MonadState:5')"></span> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Control-Monad.html#t:Monad">Monad</a> m => <a href="Control-Monad-State-Strict.html#t:MonadState">MonadState</a> (<a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m)</span> <a href="src/Control-Monad-State-Class.html#line-84" class="link">Source</a> <a href="#t:MonadState" class="selflink">#</a></td><td class="doc empty"> </td></tr><tr><td colspan="2"><div id="section.i:ic:MonadState:MonadState:5" class="inst-details hide"><div class="subs associated-types"><p class="caption">Associated Types</p><p class="src"><span class="keyword">type</span> <a href="Control-Monad-State-Strict.html#t:StateType">StateType</a> (<a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> -> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a>) :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> <a href="src/Control-Monad-State-Class.html#StateType" class="link">Source</a> <a href="#t:StateType" class="selflink">#</a></p></div> <div class="subs methods"><p class="caption">Methods</p><p class="src"><a href="#v:get">get</a> :: <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m (<a href="Control-Monad-State-Strict.html#t:StateType">StateType</a> (<a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m)) <a href="src/Control-Monad-State-Class.html#get" class="link">Source</a> <a href="#v:get" class="selflink">#</a></p><p class="src"><a href="#v:put">put</a> :: <a href="Control-Monad-State-Strict.html#t:StateType">StateType</a> (<a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m) -> <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m () <a href="src/Control-Monad-State-Class.html#put" class="link">Source</a> <a href="#v:put" class="selflink">#</a></p></div></div></td></tr><tr><td class="src clearfix"><span class="inst-left"><span id="control.i:ic:MonadState:MonadState:6" class="instance expander" onclick="toggleSection('i:ic:MonadState:MonadState:6')"></span> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Control-Monad.html#t:Monad">Monad</a> m => <a href="Control-Monad-State-Strict.html#t:MonadState">MonadState</a> (<a href="Control-Monad-State-Lazy.html#t:StateT">StateT</a> s m)</span> <a href="src/Control-Monad-State-Class.html#line-79" class="link">Source</a> <a href="#t:MonadState" class="selflink">#</a></td><td class="doc empty"> </td></tr><tr><td colspan="2"><div id="section.i:ic:MonadState:MonadState:6" class="inst-details hide"><div class="subs associated-types"><p class="caption">Associated Types</p><p class="src"><span class="keyword">type</span> <a href="Control-Monad-State-Strict.html#t:StateType">StateType</a> (<a href="Control-Monad-State-Lazy.html#t:StateT">StateT</a> s m :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> -> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a>) :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> <a href="src/Control-Monad-State-Class.html#StateType" class="link">Source</a> <a href="#t:StateType" class="selflink">#</a></p></div> <div class="subs methods"><p class="caption">Methods</p><p class="src"><a href="#v:get">get</a> :: <a href="Control-Monad-State-Lazy.html#t:StateT">StateT</a> s m (<a href="Control-Monad-State-Strict.html#t:StateType">StateType</a> (<a href="Control-Monad-State-Lazy.html#t:StateT">StateT</a> s m)) <a href="src/Control-Monad-State-Class.html#get" class="link">Source</a> <a href="#v:get" class="selflink">#</a></p><p class="src"><a href="#v:put">put</a> :: <a href="Control-Monad-State-Strict.html#t:StateType">StateType</a> (<a href="Control-Monad-State-Lazy.html#t:StateT">StateT</a> s m) -> <a href="Control-Monad-State-Lazy.html#t:StateT">StateT</a> s m () <a href="src/Control-Monad-State-Class.html#put" class="link">Source</a> <a href="#v:put" class="selflink">#</a></p></div></div></td></tr><tr><td class="src clearfix"><span class="inst-left"><span id="control.i:ic:MonadState:MonadState:7" class="instance expander" onclick="toggleSection('i:ic:MonadState:MonadState:7')"></span> <a href="Control-Monad-State-Strict.html#t:MonadState">MonadState</a> m => <a href="Control-Monad-State-Strict.html#t:MonadState">MonadState</a> (<a href="file:///usr/share/doc/ghc-doc/html/libraries/transformers-0.5.2.0/Control-Monad-Trans-Identity.html#t:IdentityT">IdentityT</a> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> m)</span> <a href="src/Control-Monad-State-Class.html#line-112" class="link">Source</a> <a href="#t:MonadState" class="selflink">#</a></td><td class="doc empty"> </td></tr><tr><td colspan="2"><div id="section.i:ic:MonadState:MonadState:7" class="inst-details hide"><div class="subs associated-types"><p class="caption">Associated Types</p><p class="src"><span class="keyword">type</span> <a href="Control-Monad-State-Strict.html#t:StateType">StateType</a> (<a href="file:///usr/share/doc/ghc-doc/html/libraries/transformers-0.5.2.0/Control-Monad-Trans-Identity.html#t:IdentityT">IdentityT</a> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> m :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> -> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a>) :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> <a href="src/Control-Monad-State-Class.html#StateType" class="link">Source</a> <a href="#t:StateType" class="selflink">#</a></p></div> <div class="subs methods"><p class="caption">Methods</p><p class="src"><a href="#v:get">get</a> :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/transformers-0.5.2.0/Control-Monad-Trans-Identity.html#t:IdentityT">IdentityT</a> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> m (<a href="Control-Monad-State-Strict.html#t:StateType">StateType</a> (<a href="file:///usr/share/doc/ghc-doc/html/libraries/transformers-0.5.2.0/Control-Monad-Trans-Identity.html#t:IdentityT">IdentityT</a> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> m)) <a href="src/Control-Monad-State-Class.html#get" class="link">Source</a> <a href="#v:get" class="selflink">#</a></p><p class="src"><a href="#v:put">put</a> :: <a href="Control-Monad-State-Strict.html#t:StateType">StateType</a> (<a href="file:///usr/share/doc/ghc-doc/html/libraries/transformers-0.5.2.0/Control-Monad-Trans-Identity.html#t:IdentityT">IdentityT</a> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> m) -> <a href="file:///usr/share/doc/ghc-doc/html/libraries/transformers-0.5.2.0/Control-Monad-Trans-Identity.html#t:IdentityT">IdentityT</a> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> m () <a href="src/Control-Monad-State-Class.html#put" class="link">Source</a> <a href="#v:put" class="selflink">#</a></p></div></div></td></tr><tr><td class="src clearfix"><span class="inst-left"><span id="control.i:ic:MonadState:MonadState:8" class="instance expander" onclick="toggleSection('i:ic:MonadState:MonadState:8')"></span> (<a href="Control-Monad-Error-Class.html#t:Error">Error</a> e, <a href="Control-Monad-State-Strict.html#t:MonadState">MonadState</a> m) => <a href="Control-Monad-State-Strict.html#t:MonadState">MonadState</a> (<a href="Control-Monad-Error.html#t:ErrorT">ErrorT</a> e m)</span> <a href="src/Control-Monad-State-Class.html#line-107" class="link">Source</a> <a href="#t:MonadState" class="selflink">#</a></td><td class="doc empty"> </td></tr><tr><td colspan="2"><div id="section.i:ic:MonadState:MonadState:8" class="inst-details hide"><div class="subs associated-types"><p class="caption">Associated Types</p><p class="src"><span class="keyword">type</span> <a href="Control-Monad-State-Strict.html#t:StateType">StateType</a> (<a href="Control-Monad-Error.html#t:ErrorT">ErrorT</a> e m :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> -> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a>) :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> <a href="src/Control-Monad-State-Class.html#StateType" class="link">Source</a> <a href="#t:StateType" class="selflink">#</a></p></div> <div class="subs methods"><p class="caption">Methods</p><p class="src"><a href="#v:get">get</a> :: <a href="Control-Monad-Error.html#t:ErrorT">ErrorT</a> e m (<a href="Control-Monad-State-Strict.html#t:StateType">StateType</a> (<a href="Control-Monad-Error.html#t:ErrorT">ErrorT</a> e m)) <a href="src/Control-Monad-State-Class.html#get" class="link">Source</a> <a href="#v:get" class="selflink">#</a></p><p class="src"><a href="#v:put">put</a> :: <a href="Control-Monad-State-Strict.html#t:StateType">StateType</a> (<a href="Control-Monad-Error.html#t:ErrorT">ErrorT</a> e m) -> <a href="Control-Monad-Error.html#t:ErrorT">ErrorT</a> e m () <a href="src/Control-Monad-State-Class.html#put" class="link">Source</a> <a href="#v:put" class="selflink">#</a></p></div></div></td></tr><tr><td class="src clearfix"><span class="inst-left"><span id="control.i:ic:MonadState:MonadState:9" class="instance expander" onclick="toggleSection('i:ic:MonadState:MonadState:9')"></span> <a href="Control-Monad-State-Strict.html#t:MonadState">MonadState</a> m => <a href="Control-Monad-State-Strict.html#t:MonadState">MonadState</a> (<a href="Control-Monad-Reader.html#t:ReaderT">ReaderT</a> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> r m)</span> <a href="src/Control-Monad-State-Class.html#line-127" class="link">Source</a> <a href="#t:MonadState" class="selflink">#</a></td><td class="doc empty"> </td></tr><tr><td colspan="2"><div id="section.i:ic:MonadState:MonadState:9" class="inst-details hide"><div class="subs associated-types"><p class="caption">Associated Types</p><p class="src"><span class="keyword">type</span> <a href="Control-Monad-State-Strict.html#t:StateType">StateType</a> (<a href="Control-Monad-Reader.html#t:ReaderT">ReaderT</a> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> r m :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> -> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a>) :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> <a href="src/Control-Monad-State-Class.html#StateType" class="link">Source</a> <a href="#t:StateType" class="selflink">#</a></p></div> <div class="subs methods"><p class="caption">Methods</p><p class="src"><a href="#v:get">get</a> :: <a href="Control-Monad-Reader.html#t:ReaderT">ReaderT</a> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> r m (<a href="Control-Monad-State-Strict.html#t:StateType">StateType</a> (<a href="Control-Monad-Reader.html#t:ReaderT">ReaderT</a> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> r m)) <a href="src/Control-Monad-State-Class.html#get" class="link">Source</a> <a href="#v:get" class="selflink">#</a></p><p class="src"><a href="#v:put">put</a> :: <a href="Control-Monad-State-Strict.html#t:StateType">StateType</a> (<a href="Control-Monad-Reader.html#t:ReaderT">ReaderT</a> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> r m) -> <a href="Control-Monad-Reader.html#t:ReaderT">ReaderT</a> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> r m () <a href="src/Control-Monad-State-Class.html#put" class="link">Source</a> <a href="#v:put" class="selflink">#</a></p></div></div></td></tr><tr><td class="src clearfix"><span class="inst-left"><span id="control.i:ic:MonadState:MonadState:10" class="instance expander" onclick="toggleSection('i:ic:MonadState:MonadState:10')"></span> <a href="Control-Monad-State-Strict.html#t:MonadState">MonadState</a> m => <a href="Control-Monad-State-Strict.html#t:MonadState">MonadState</a> (<a href="Control-Monad-Cont.html#t:ContT">ContT</a> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> r m)</span> <a href="src/Control-Monad-State-Class.html#line-102" class="link">Source</a> <a href="#t:MonadState" class="selflink">#</a></td><td class="doc empty"> </td></tr><tr><td colspan="2"><div id="section.i:ic:MonadState:MonadState:10" class="inst-details hide"><div class="subs associated-types"><p class="caption">Associated Types</p><p class="src"><span class="keyword">type</span> <a href="Control-Monad-State-Strict.html#t:StateType">StateType</a> (<a href="Control-Monad-Cont.html#t:ContT">ContT</a> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> r m :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> -> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a>) :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> <a href="src/Control-Monad-State-Class.html#StateType" class="link">Source</a> <a href="#t:StateType" class="selflink">#</a></p></div> <div class="subs methods"><p class="caption">Methods</p><p class="src"><a href="#v:get">get</a> :: <a href="Control-Monad-Cont.html#t:ContT">ContT</a> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> r m (<a href="Control-Monad-State-Strict.html#t:StateType">StateType</a> (<a href="Control-Monad-Cont.html#t:ContT">ContT</a> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> r m)) <a href="src/Control-Monad-State-Class.html#get" class="link">Source</a> <a href="#v:get" class="selflink">#</a></p><p class="src"><a href="#v:put">put</a> :: <a href="Control-Monad-State-Strict.html#t:StateType">StateType</a> (<a href="Control-Monad-Cont.html#t:ContT">ContT</a> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> r m) -> <a href="Control-Monad-Cont.html#t:ContT">ContT</a> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> r m () <a href="src/Control-Monad-State-Class.html#put" class="link">Source</a> <a href="#v:put" class="selflink">#</a></p></div></div></td></tr><tr><td class="src clearfix"><span class="inst-left"><span id="control.i:ic:MonadState:MonadState:11" class="instance expander" onclick="toggleSection('i:ic:MonadState:MonadState:11')"></span> (<a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Control-Monad.html#t:Monad">Monad</a> m, <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Monoid.html#t:Monoid">Monoid</a> w) => <a href="Control-Monad-State-Strict.html#t:MonadState">MonadState</a> (<a href="Control-Monad-RWS-Strict.html#t:RWST">RWST</a> r w s m)</span> <a href="src/Control-Monad-State-Class.html#line-94" class="link">Source</a> <a href="#t:MonadState" class="selflink">#</a></td><td class="doc empty"> </td></tr><tr><td colspan="2"><div id="section.i:ic:MonadState:MonadState:11" class="inst-details hide"><div class="subs associated-types"><p class="caption">Associated Types</p><p class="src"><span class="keyword">type</span> <a href="Control-Monad-State-Strict.html#t:StateType">StateType</a> (<a href="Control-Monad-RWS-Strict.html#t:RWST">RWST</a> r w s m :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> -> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a>) :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> <a href="src/Control-Monad-State-Class.html#StateType" class="link">Source</a> <a href="#t:StateType" class="selflink">#</a></p></div> <div class="subs methods"><p class="caption">Methods</p><p class="src"><a href="#v:get">get</a> :: <a href="Control-Monad-RWS-Strict.html#t:RWST">RWST</a> r w s m (<a href="Control-Monad-State-Strict.html#t:StateType">StateType</a> (<a href="Control-Monad-RWS-Strict.html#t:RWST">RWST</a> r w s m)) <a href="src/Control-Monad-State-Class.html#get" class="link">Source</a> <a href="#v:get" class="selflink">#</a></p><p class="src"><a href="#v:put">put</a> :: <a href="Control-Monad-State-Strict.html#t:StateType">StateType</a> (<a href="Control-Monad-RWS-Strict.html#t:RWST">RWST</a> r w s m) -> <a href="Control-Monad-RWS-Strict.html#t:RWST">RWST</a> r w s m () <a href="src/Control-Monad-State-Class.html#put" class="link">Source</a> <a href="#v:put" class="selflink">#</a></p></div></div></td></tr><tr><td class="src clearfix"><span class="inst-left"><span id="control.i:ic:MonadState:MonadState:12" class="instance expander" onclick="toggleSection('i:ic:MonadState:MonadState:12')"></span> (<a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Control-Monad.html#t:Monad">Monad</a> m, <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Monoid.html#t:Monoid">Monoid</a> w) => <a href="Control-Monad-State-Strict.html#t:MonadState">MonadState</a> (<a href="Control-Monad-RWS-Lazy.html#t:RWST">RWST</a> r w s m)</span> <a href="src/Control-Monad-State-Class.html#line-89" class="link">Source</a> <a href="#t:MonadState" class="selflink">#</a></td><td class="doc empty"> </td></tr><tr><td colspan="2"><div id="section.i:ic:MonadState:MonadState:12" class="inst-details hide"><div class="subs associated-types"><p class="caption">Associated Types</p><p class="src"><span class="keyword">type</span> <a href="Control-Monad-State-Strict.html#t:StateType">StateType</a> (<a href="Control-Monad-RWS-Lazy.html#t:RWST">RWST</a> r w s m :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> -> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a>) :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> <a href="src/Control-Monad-State-Class.html#StateType" class="link">Source</a> <a href="#t:StateType" class="selflink">#</a></p></div> <div class="subs methods"><p class="caption">Methods</p><p class="src"><a href="#v:get">get</a> :: <a href="Control-Monad-RWS-Lazy.html#t:RWST">RWST</a> r w s m (<a href="Control-Monad-State-Strict.html#t:StateType">StateType</a> (<a href="Control-Monad-RWS-Lazy.html#t:RWST">RWST</a> r w s m)) <a href="src/Control-Monad-State-Class.html#get" class="link">Source</a> <a href="#v:get" class="selflink">#</a></p><p class="src"><a href="#v:put">put</a> :: <a href="Control-Monad-State-Strict.html#t:StateType">StateType</a> (<a href="Control-Monad-RWS-Lazy.html#t:RWST">RWST</a> r w s m) -> <a href="Control-Monad-RWS-Lazy.html#t:RWST">RWST</a> r w s m () <a href="src/Control-Monad-State-Class.html#put" class="link">Source</a> <a href="#v:put" class="selflink">#</a></p></div></div></td></tr></table></div></div></div><div class="top"><p class="src"><a id="v:modify" class="def">modify</a> :: <a href="Control-Monad-State-Strict.html#t:MonadState">MonadState</a> m => (<a href="Control-Monad-State-Strict.html#t:StateType">StateType</a> m -> <a href="Control-Monad-State-Strict.html#t:StateType">StateType</a> m) -> m () <a href="src/Control-Monad-State-Class.html#modify" class="link">Source</a> <a href="#v:modify" class="selflink">#</a></p><div class="doc"><p>Monadic state transformer.</p><p>Maps an old state to a new state inside a state monad.
The old state is thrown away.</p><pre> Main> :t modify ((+1) :: Int -> Int)
modify (...) :: (MonadState Int a) => a ()</pre><p>This says that <code>modify (+1)</code> acts over any
Monad that is a member of the <code>MonadState</code> class,
with an <code>Int</code> state.</p></div></div><div class="top"><p class="src"><a id="v:gets" class="def">gets</a> :: <a href="Control-Monad-State-Strict.html#t:MonadState">MonadState</a> m => (<a href="Control-Monad-State-Strict.html#t:StateType">StateType</a> m -> a) -> m a <a href="src/Control-Monad-State-Class.html#gets" class="link">Source</a> <a href="#v:gets" class="selflink">#</a></p><div class="doc"><p>Gets specific component of the state, using a projection function
supplied.</p></div></div><h1 id="g:2">The State monad</h1><div class="top"><p class="src"><span class="keyword">type</span> <a id="t:State" class="def">State</a> s = <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Functor-Identity.html#t:Identity">Identity</a> <a href="#t:State" class="selflink">#</a></p><div class="doc"><p>A state monad parameterized by the type <code>s</code> of the state to carry.</p><p>The <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Control-Monad.html#v:return">return</a></code> function leaves the state unchanged, while <code>>>=</code> uses
the final state of the first computation as the initial state of
the second.</p></div></div><div class="top"><p class="src"><a id="v:runState" class="def">runState</a> <a href="#v:runState" class="selflink">#</a></p><div class="subs arguments"><p class="caption">Arguments</p><table><tr><td class="src">:: <a href="Control-Monad-State-Strict.html#t:State">State</a> s a</td><td class="doc"><p>state-passing computation to execute</p></td></tr><tr><td class="src">-> s</td><td class="doc"><p>initial state</p></td></tr><tr><td class="src">-> (a, s)</td><td class="doc"><p>return value and final state</p></td></tr></table></div><div class="doc"><p>Unwrap a state monad computation as a function.
(The inverse of <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/transformers-0.5.2.0/Control-Monad-Trans-State-Strict.html#v:state">state</a></code>.)</p></div></div><div class="top"><p class="src"><a id="v:evalState" class="def">evalState</a> <a href="#v:evalState" class="selflink">#</a></p><div class="subs arguments"><p class="caption">Arguments</p><table><tr><td class="src">:: <a href="Control-Monad-State-Strict.html#t:State">State</a> s a</td><td class="doc"><p>state-passing computation to execute</p></td></tr><tr><td class="src">-> s</td><td class="doc"><p>initial value</p></td></tr><tr><td class="src">-> a</td><td class="doc"><p>return value of the state computation</p></td></tr></table></div><div class="doc"><p>Evaluate a state computation with the given initial state
and return the final value, discarding the final state.</p><ul><li><pre><code><a href="Control-Monad-State-Strict.html#v:evalState">evalState</a></code> m s = <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Tuple.html#v:fst">fst</a></code> (<code><a href="Control-Monad-State-Strict.html#v:runState">runState</a></code> m s)</pre></li></ul></div></div><div class="top"><p class="src"><a id="v:execState" class="def">execState</a> <a href="#v:execState" class="selflink">#</a></p><div class="subs arguments"><p class="caption">Arguments</p><table><tr><td class="src">:: <a href="Control-Monad-State-Strict.html#t:State">State</a> s a</td><td class="doc"><p>state-passing computation to execute</p></td></tr><tr><td class="src">-> s</td><td class="doc"><p>initial value</p></td></tr><tr><td class="src">-> s</td><td class="doc"><p>final state</p></td></tr></table></div><div class="doc"><p>Evaluate a state computation with the given initial state
and return the final state, discarding the final value.</p><ul><li><pre><code><a href="Control-Monad-State-Strict.html#v:execState">execState</a></code> m s = <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Tuple.html#v:snd">snd</a></code> (<code><a href="Control-Monad-State-Strict.html#v:runState">runState</a></code> m s)</pre></li></ul></div></div><div class="top"><p class="src"><a id="v:mapState" class="def">mapState</a> :: ((a, s) -> (b, s)) -> <a href="Control-Monad-State-Strict.html#t:State">State</a> s a -> <a href="Control-Monad-State-Strict.html#t:State">State</a> s b <a href="#v:mapState" class="selflink">#</a></p><div class="doc"><p>Map both the return value and final state of a computation using
the given function.</p><ul><li><pre><code><a href="Control-Monad-State-Strict.html#v:runState">runState</a></code> (<code><a href="Control-Monad-State-Strict.html#v:mapState">mapState</a></code> f m) = f . <code><a href="Control-Monad-State-Strict.html#v:runState">runState</a></code> m</pre></li></ul></div></div><div class="top"><p class="src"><a id="v:withState" class="def">withState</a> :: (s -> s) -> <a href="Control-Monad-State-Strict.html#t:State">State</a> s a -> <a href="Control-Monad-State-Strict.html#t:State">State</a> s a <a href="#v:withState" class="selflink">#</a></p><div class="doc"><p><code><code><a href="Control-Monad-State-Strict.html#v:withState">withState</a></code> f m</code> executes action <code>m</code> on a state modified by
applying <code>f</code>.</p><ul><li><pre><code><a href="Control-Monad-State-Strict.html#v:withState">withState</a></code> f m = <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/transformers-0.5.2.0/Control-Monad-Trans-State-Strict.html#v:modify">modify</a></code> f >> m</pre></li></ul></div></div><h1 id="g:3">The StateT monad transformer</h1><div class="top"><p class="src"><span class="keyword">newtype</span> <a id="t:StateT" class="def">StateT</a> s m a :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> -> (<a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> -> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a>) -> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> -> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> <a href="#t:StateT" class="selflink">#</a></p><div class="doc"><p>A state transformer monad parameterized by:</p><ul><li><code>s</code> - The state.</li><li><code>m</code> - The inner monad.</li></ul><p>The <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Control-Monad.html#v:return">return</a></code> function leaves the state unchanged, while <code>>>=</code> uses
the final state of the first computation as the initial state of
the second.</p></div><div class="subs constructors"><p class="caption">Constructors</p><table><tr><td class="src"><a id="v:StateT" class="def">StateT</a></td><td class="doc empty"> </td></tr><tr><td colspan="2"><div class="subs fields"><p class="caption">Fields</p><ul><li><dfn class="src"><a id="v:runStateT" class="def">runStateT</a> :: s -> m (a, s)</dfn><div class="doc empty"> </div></li></ul></div></td></tr></table></div><div class="subs instances"><p id="control.i:StateT" class="caption collapser" onclick="toggleSection('i:StateT')">Instances</p><div id="section.i:StateT" class="show"><table><tr><td class="src clearfix"><span class="inst-left"><span id="control.i:id:StateT:MonadTrans:1" class="instance expander" onclick="toggleSection('i:id:StateT:MonadTrans:1')"></span> <a href="file:///usr/share/doc/ghc-doc/html/libraries/transformers-0.5.2.0/Control-Monad-Trans-Class.html#t:MonadTrans">MonadTrans</a> (<a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s)</span></td><td class="doc empty"> </td></tr><tr><td colspan="2"><div id="section.i:id:StateT:MonadTrans:1" class="inst-details hide"><div class="subs methods"><p class="caption">Methods</p><p class="src"><a href="#v:lift">lift</a> :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Control-Monad.html#t:Monad">Monad</a> m => m a -> <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m a <a href="#v:lift" class="selflink">#</a></p></div></div></td></tr><tr><td class="src clearfix"><span class="inst-left"><span id="control.i:id:StateT:Monad:2" class="instance expander" onclick="toggleSection('i:id:StateT:Monad:2')"></span> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Control-Monad.html#t:Monad">Monad</a> m => <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Control-Monad.html#t:Monad">Monad</a> (<a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m)</span></td><td class="doc empty"> </td></tr><tr><td colspan="2"><div id="section.i:id:StateT:Monad:2" class="inst-details hide"><div class="subs methods"><p class="caption">Methods</p><p class="src"><a href="#v:-62--62--61-">(>>=)</a> :: <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m a -> (a -> <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m b) -> <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m b <a href="#v:-62--62--61-" class="selflink">#</a></p><p class="src"><a href="#v:-62--62-">(>>)</a> :: <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m a -> <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m b -> <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m b <a href="#v:-62--62-" class="selflink">#</a></p><p class="src"><a href="#v:return">return</a> :: a -> <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m a <a href="#v:return" class="selflink">#</a></p><p class="src"><a href="#v:fail">fail</a> :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-String.html#t:String">String</a> -> <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m a <a href="#v:fail" class="selflink">#</a></p></div></div></td></tr><tr><td class="src clearfix"><span class="inst-left"><span id="control.i:id:StateT:Functor:3" class="instance expander" onclick="toggleSection('i:id:StateT:Functor:3')"></span> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Functor.html#t:Functor">Functor</a> m => <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Functor.html#t:Functor">Functor</a> (<a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m)</span></td><td class="doc empty"> </td></tr><tr><td colspan="2"><div id="section.i:id:StateT:Functor:3" class="inst-details hide"><div class="subs methods"><p class="caption">Methods</p><p class="src"><a href="#v:fmap">fmap</a> :: (a -> b) -> <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m a -> <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m b <a href="#v:fmap" class="selflink">#</a></p><p class="src"><a href="#v:-60--36-">(<$)</a> :: a -> <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m b -> <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m a <a href="#v:-60--36-" class="selflink">#</a></p></div></div></td></tr><tr><td class="src clearfix"><span class="inst-left"><span id="control.i:id:StateT:MonadFix:4" class="instance expander" onclick="toggleSection('i:id:StateT:MonadFix:4')"></span> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Control-Monad-Fix.html#t:MonadFix">MonadFix</a> m => <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Control-Monad-Fix.html#t:MonadFix">MonadFix</a> (<a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m)</span></td><td class="doc empty"> </td></tr><tr><td colspan="2"><div id="section.i:id:StateT:MonadFix:4" class="inst-details hide"><div class="subs methods"><p class="caption">Methods</p><p class="src"><a href="#v:mfix">mfix</a> :: (a -> <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m a) -> <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m a <a href="#v:mfix" class="selflink">#</a></p></div></div></td></tr><tr><td class="src clearfix"><span class="inst-left"><span id="control.i:id:StateT:MonadFail:5" class="instance expander" onclick="toggleSection('i:id:StateT:MonadFail:5')"></span> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Control-Monad-Fail.html#t:MonadFail">MonadFail</a> m => <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Control-Monad-Fail.html#t:MonadFail">MonadFail</a> (<a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m)</span></td><td class="doc empty"> </td></tr><tr><td colspan="2"><div id="section.i:id:StateT:MonadFail:5" class="inst-details hide"><div class="subs methods"><p class="caption">Methods</p><p class="src"><a href="#v:fail">fail</a> :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-String.html#t:String">String</a> -> <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m a <a href="#v:fail" class="selflink">#</a></p></div></div></td></tr><tr><td class="src clearfix"><span class="inst-left"><span id="control.i:id:StateT:Applicative:6" class="instance expander" onclick="toggleSection('i:id:StateT:Applicative:6')"></span> (<a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Functor.html#t:Functor">Functor</a> m, <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Control-Monad.html#t:Monad">Monad</a> m) => <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Control-Applicative.html#t:Applicative">Applicative</a> (<a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m)</span></td><td class="doc empty"> </td></tr><tr><td colspan="2"><div id="section.i:id:StateT:Applicative:6" class="inst-details hide"><div class="subs methods"><p class="caption">Methods</p><p class="src"><a href="#v:pure">pure</a> :: a -> <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m a <a href="#v:pure" class="selflink">#</a></p><p class="src"><a href="#v:-60--42--62-">(<*>)</a> :: <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m (a -> b) -> <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m a -> <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m b <a href="#v:-60--42--62-" class="selflink">#</a></p><p class="src"><a href="#v:-42--62-">(*>)</a> :: <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m a -> <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m b -> <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m b <a href="#v:-42--62-" class="selflink">#</a></p><p class="src"><a href="#v:-60--42-">(<*)</a> :: <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m a -> <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m b -> <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m a <a href="#v:-60--42-" class="selflink">#</a></p></div></div></td></tr><tr><td class="src clearfix"><span class="inst-left"><span id="control.i:id:StateT:MonadIO:7" class="instance expander" onclick="toggleSection('i:id:StateT:MonadIO:7')"></span> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Control-Monad-IO-Class.html#t:MonadIO">MonadIO</a> m => <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Control-Monad-IO-Class.html#t:MonadIO">MonadIO</a> (<a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m)</span></td><td class="doc empty"> </td></tr><tr><td colspan="2"><div id="section.i:id:StateT:MonadIO:7" class="inst-details hide"><div class="subs methods"><p class="caption">Methods</p><p class="src"><a href="#v:liftIO">liftIO</a> :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> a -> <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m a <a href="#v:liftIO" class="selflink">#</a></p></div></div></td></tr><tr><td class="src clearfix"><span class="inst-left"><span id="control.i:id:StateT:Alternative:8" class="instance expander" onclick="toggleSection('i:id:StateT:Alternative:8')"></span> (<a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Functor.html#t:Functor">Functor</a> m, <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Control-Monad.html#t:MonadPlus">MonadPlus</a> m) => <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Control-Applicative.html#t:Alternative">Alternative</a> (<a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m)</span></td><td class="doc empty"> </td></tr><tr><td colspan="2"><div id="section.i:id:StateT:Alternative:8" class="inst-details hide"><div class="subs methods"><p class="caption">Methods</p><p class="src"><a href="#v:empty">empty</a> :: <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m a <a href="#v:empty" class="selflink">#</a></p><p class="src"><a href="#v:-60--124--62-">(<|>)</a> :: <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m a -> <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m a -> <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m a <a href="#v:-60--124--62-" class="selflink">#</a></p><p class="src"><a href="#v:some">some</a> :: <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m a -> <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m [a] <a href="#v:some" class="selflink">#</a></p><p class="src"><a href="#v:many">many</a> :: <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m a -> <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m [a] <a href="#v:many" class="selflink">#</a></p></div></div></td></tr><tr><td class="src clearfix"><span class="inst-left"><span id="control.i:id:StateT:MonadPlus:9" class="instance expander" onclick="toggleSection('i:id:StateT:MonadPlus:9')"></span> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Control-Monad.html#t:MonadPlus">MonadPlus</a> m => <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Control-Monad.html#t:MonadPlus">MonadPlus</a> (<a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m)</span></td><td class="doc empty"> </td></tr><tr><td colspan="2"><div id="section.i:id:StateT:MonadPlus:9" class="inst-details hide"><div class="subs methods"><p class="caption">Methods</p><p class="src"><a href="#v:mzero">mzero</a> :: <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m a <a href="#v:mzero" class="selflink">#</a></p><p class="src"><a href="#v:mplus">mplus</a> :: <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m a -> <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m a -> <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m a <a href="#v:mplus" class="selflink">#</a></p></div></div></td></tr><tr><td class="src clearfix"><span class="inst-left"><span id="control.i:id:StateT:MonadCont:10" class="instance expander" onclick="toggleSection('i:id:StateT:MonadCont:10')"></span> <a href="Control-Monad-Cont-Class.html#t:MonadCont">MonadCont</a> m => <a href="Control-Monad-Cont-Class.html#t:MonadCont">MonadCont</a> (<a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m)</span> <a href="src/Control-Monad-Cont-Class.html#line-122" class="link">Source</a> <a href="#t:MonadCont" class="selflink">#</a></td><td class="doc empty"> </td></tr><tr><td colspan="2"><div id="section.i:id:StateT:MonadCont:10" class="inst-details hide"><div class="subs methods"><p class="caption">Methods</p><p class="src"><a href="#v:callCC">callCC</a> :: ((a -> <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m b) -> <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m a) -> <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m a <a href="src/Control-Monad-Cont-Class.html#callCC" class="link">Source</a> <a href="#v:callCC" class="selflink">#</a></p></div></div></td></tr><tr><td class="src clearfix"><span class="inst-left"><span id="control.i:id:StateT:MonadError:11" class="instance expander" onclick="toggleSection('i:id:StateT:MonadError:11')"></span> <a href="Control-Monad-Error-Class.html#t:MonadError">MonadError</a> m => <a href="Control-Monad-Error-Class.html#t:MonadError">MonadError</a> (<a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m)</span> <a href="src/Control-Monad-Error-Class.html#line-151" class="link">Source</a> <a href="#t:MonadError" class="selflink">#</a></td><td class="doc empty"> </td></tr><tr><td colspan="2"><div id="section.i:id:StateT:MonadError:11" class="inst-details hide"><div class="subs associated-types"><p class="caption">Associated Types</p><p class="src"><span class="keyword">type</span> <a href="Control-Monad-Error-Class.html#t:ErrorType">ErrorType</a> (<a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> -> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a>) :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> <a href="src/Control-Monad-Error-Class.html#ErrorType" class="link">Source</a> <a href="#t:ErrorType" class="selflink">#</a></p></div> <div class="subs methods"><p class="caption">Methods</p><p class="src"><a href="#v:throwError">throwError</a> :: <a href="Control-Monad-Error-Class.html#t:ErrorType">ErrorType</a> (<a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m) -> <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m a <a href="src/Control-Monad-Error-Class.html#throwError" class="link">Source</a> <a href="#v:throwError" class="selflink">#</a></p><p class="src"><a href="#v:catchError">catchError</a> :: <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m a -> (<a href="Control-Monad-Error-Class.html#t:ErrorType">ErrorType</a> (<a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m) -> <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m a) -> <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m a <a href="src/Control-Monad-Error-Class.html#catchError" class="link">Source</a> <a href="#v:catchError" class="selflink">#</a></p></div></div></td></tr><tr><td class="src clearfix"><span class="inst-left"><span id="control.i:id:StateT:MonadReader:12" class="instance expander" onclick="toggleSection('i:id:StateT:MonadReader:12')"></span> <a href="Control-Monad-Reader-Class.html#t:MonadReader">MonadReader</a> m => <a href="Control-Monad-Reader-Class.html#t:MonadReader">MonadReader</a> (<a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m)</span> <a href="src/Control-Monad-Reader-Class.html#line-144" class="link">Source</a> <a href="#t:MonadReader" class="selflink">#</a></td><td class="doc empty"> </td></tr><tr><td colspan="2"><div id="section.i:id:StateT:MonadReader:12" class="inst-details hide"><div class="subs associated-types"><p class="caption">Associated Types</p><p class="src"><span class="keyword">type</span> <a href="Control-Monad-Reader-Class.html#t:EnvType">EnvType</a> (<a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> -> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a>) :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> <a href="src/Control-Monad-Reader-Class.html#EnvType" class="link">Source</a> <a href="#t:EnvType" class="selflink">#</a></p></div> <div class="subs methods"><p class="caption">Methods</p><p class="src"><a href="#v:ask">ask</a> :: <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m (<a href="Control-Monad-Reader-Class.html#t:EnvType">EnvType</a> (<a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m)) <a href="src/Control-Monad-Reader-Class.html#ask" class="link">Source</a> <a href="#v:ask" class="selflink">#</a></p><p class="src"><a href="#v:local">local</a> :: (<a href="Control-Monad-Reader-Class.html#t:EnvType">EnvType</a> (<a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m) -> <a href="Control-Monad-Reader-Class.html#t:EnvType">EnvType</a> (<a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m)) -> <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m a -> <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m a <a href="src/Control-Monad-Reader-Class.html#local" class="link">Source</a> <a href="#v:local" class="selflink">#</a></p></div></div></td></tr><tr><td class="src clearfix"><span class="inst-left"><span id="control.i:id:StateT:MonadState:13" class="instance expander" onclick="toggleSection('i:id:StateT:MonadState:13')"></span> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Control-Monad.html#t:Monad">Monad</a> m => <a href="Control-Monad-State-Strict.html#t:MonadState">MonadState</a> (<a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m)</span> <a href="src/Control-Monad-State-Class.html#line-84" class="link">Source</a> <a href="#t:MonadState" class="selflink">#</a></td><td class="doc empty"> </td></tr><tr><td colspan="2"><div id="section.i:id:StateT:MonadState:13" class="inst-details hide"><div class="subs associated-types"><p class="caption">Associated Types</p><p class="src"><span class="keyword">type</span> <a href="Control-Monad-State-Strict.html#t:StateType">StateType</a> (<a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> -> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a>) :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> <a href="src/Control-Monad-State-Class.html#StateType" class="link">Source</a> <a href="#t:StateType" class="selflink">#</a></p></div> <div class="subs methods"><p class="caption">Methods</p><p class="src"><a href="#v:get">get</a> :: <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m (<a href="Control-Monad-State-Strict.html#t:StateType">StateType</a> (<a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m)) <a href="src/Control-Monad-State-Class.html#get" class="link">Source</a> <a href="#v:get" class="selflink">#</a></p><p class="src"><a href="#v:put">put</a> :: <a href="Control-Monad-State-Strict.html#t:StateType">StateType</a> (<a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m) -> <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m () <a href="src/Control-Monad-State-Class.html#put" class="link">Source</a> <a href="#v:put" class="selflink">#</a></p></div></div></td></tr><tr><td class="src clearfix"><span class="inst-left"><span id="control.i:id:StateT:MonadWriter:14" class="instance expander" onclick="toggleSection('i:id:StateT:MonadWriter:14')"></span> <a href="Control-Monad-Writer-Class.html#t:MonadWriter">MonadWriter</a> m => <a href="Control-Monad-Writer-Class.html#t:MonadWriter">MonadWriter</a> (<a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m)</span> <a href="src/Control-Monad-Writer-Class.html#line-130" class="link">Source</a> <a href="#t:MonadWriter" class="selflink">#</a></td><td class="doc empty"> </td></tr><tr><td colspan="2"><div id="section.i:id:StateT:MonadWriter:14" class="inst-details hide"><div class="subs associated-types"><p class="caption">Associated Types</p><p class="src"><span class="keyword">type</span> <a href="Control-Monad-Writer-Class.html#t:WriterType">WriterType</a> (<a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> -> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a>) :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> <a href="src/Control-Monad-Writer-Class.html#WriterType" class="link">Source</a> <a href="#t:WriterType" class="selflink">#</a></p></div> <div class="subs methods"><p class="caption">Methods</p><p class="src"><a href="#v:tell">tell</a> :: <a href="Control-Monad-Writer-Class.html#t:WriterType">WriterType</a> (<a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m) -> <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m () <a href="src/Control-Monad-Writer-Class.html#tell" class="link">Source</a> <a href="#v:tell" class="selflink">#</a></p><p class="src"><a href="#v:listen">listen</a> :: <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m a -> <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m (a, <a href="Control-Monad-Writer-Class.html#t:WriterType">WriterType</a> (<a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m)) <a href="src/Control-Monad-Writer-Class.html#listen" class="link">Source</a> <a href="#v:listen" class="selflink">#</a></p><p class="src"><a href="#v:pass">pass</a> :: <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m (a, <a href="Control-Monad-Writer-Class.html#t:WriterType">WriterType</a> (<a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m) -> <a href="Control-Monad-Writer-Class.html#t:WriterType">WriterType</a> (<a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m)) -> <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m a <a href="src/Control-Monad-Writer-Class.html#pass" class="link">Source</a> <a href="#v:pass" class="selflink">#</a></p></div></div></td></tr><tr><td class="src clearfix"><span class="inst-left"><span id="control.i:id:StateT:ErrorType:15" class="instance expander" onclick="toggleSection('i:id:StateT:ErrorType:15')"></span> <span class="keyword">type</span> <a href="Control-Monad-Error-Class.html#t:ErrorType">ErrorType</a> (<a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m)</span> <a href="src/Control-Monad-Error-Class.html#line-152" class="link">Source</a> <a href="#t:ErrorType" class="selflink">#</a></td><td class="doc empty"> </td></tr><tr><td colspan="2"><div id="section.i:id:StateT:ErrorType:15" class="inst-details hide"><div class="src"><span class="keyword">type</span> <a href="Control-Monad-Error-Class.html#t:ErrorType">ErrorType</a> (<a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m) = <a href="Control-Monad-Error-Class.html#t:ErrorType">ErrorType</a> m</div></div></td></tr><tr><td class="src clearfix"><span class="inst-left"><span id="control.i:id:StateT:EnvType:16" class="instance expander" onclick="toggleSection('i:id:StateT:EnvType:16')"></span> <span class="keyword">type</span> <a href="Control-Monad-Reader-Class.html#t:EnvType">EnvType</a> (<a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m)</span> <a href="src/Control-Monad-Reader-Class.html#line-145" class="link">Source</a> <a href="#t:EnvType" class="selflink">#</a></td><td class="doc empty"> </td></tr><tr><td colspan="2"><div id="section.i:id:StateT:EnvType:16" class="inst-details hide"><div class="src"><span class="keyword">type</span> <a href="Control-Monad-Reader-Class.html#t:EnvType">EnvType</a> (<a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m) = <a href="Control-Monad-Reader-Class.html#t:EnvType">EnvType</a> m</div></div></td></tr><tr><td class="src clearfix"><span class="inst-left"><span id="control.i:id:StateT:StateType:17" class="instance expander" onclick="toggleSection('i:id:StateT:StateType:17')"></span> <span class="keyword">type</span> <a href="Control-Monad-State-Strict.html#t:StateType">StateType</a> (<a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m)</span> <a href="src/Control-Monad-State-Class.html#line-85" class="link">Source</a> <a href="#t:StateType" class="selflink">#</a></td><td class="doc empty"> </td></tr><tr><td colspan="2"><div id="section.i:id:StateT:StateType:17" class="inst-details hide"><div class="src"><span class="keyword">type</span> <a href="Control-Monad-State-Strict.html#t:StateType">StateType</a> (<a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m) = s</div></div></td></tr><tr><td class="src clearfix"><span class="inst-left"><span id="control.i:id:StateT:WriterType:18" class="instance expander" onclick="toggleSection('i:id:StateT:WriterType:18')"></span> <span class="keyword">type</span> <a href="Control-Monad-Writer-Class.html#t:WriterType">WriterType</a> (<a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m)</span> <a href="src/Control-Monad-Writer-Class.html#line-131" class="link">Source</a> <a href="#t:WriterType" class="selflink">#</a></td><td class="doc empty"> </td></tr><tr><td colspan="2"><div id="section.i:id:StateT:WriterType:18" class="inst-details hide"><div class="src"><span class="keyword">type</span> <a href="Control-Monad-Writer-Class.html#t:WriterType">WriterType</a> (<a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m) = <a href="Control-Monad-Writer-Class.html#t:WriterType">WriterType</a> m</div></div></td></tr></table></div></div></div><div class="top"><p class="src"><a id="v:evalStateT" class="def">evalStateT</a> :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Control-Monad.html#t:Monad">Monad</a> m => <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m a -> s -> m a <a href="#v:evalStateT" class="selflink">#</a></p><div class="doc"><p>Evaluate a state computation with the given initial state
and return the final value, discarding the final state.</p><ul><li><pre><code><a href="Control-Monad-State-Strict.html#v:evalStateT">evalStateT</a></code> m s = <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Control-Monad.html#v:liftM">liftM</a></code> <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Tuple.html#v:fst">fst</a></code> (<code><a href="Control-Monad-State-Strict.html#v:runStateT">runStateT</a></code> m s)</pre></li></ul></div></div><div class="top"><p class="src"><a id="v:execStateT" class="def">execStateT</a> :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Control-Monad.html#t:Monad">Monad</a> m => <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m a -> s -> m s <a href="#v:execStateT" class="selflink">#</a></p><div class="doc"><p>Evaluate a state computation with the given initial state
and return the final state, discarding the final value.</p><ul><li><pre><code><a href="Control-Monad-State-Strict.html#v:execStateT">execStateT</a></code> m s = <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Control-Monad.html#v:liftM">liftM</a></code> <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Tuple.html#v:snd">snd</a></code> (<code><a href="Control-Monad-State-Strict.html#v:runStateT">runStateT</a></code> m s)</pre></li></ul></div></div><div class="top"><p class="src"><a id="v:mapStateT" class="def">mapStateT</a> :: (m (a, s) -> n (b, s)) -> <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m a -> <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s n b <a href="#v:mapStateT" class="selflink">#</a></p><div class="doc"><p>Map both the return value and final state of a computation using
the given function.</p><ul><li><pre><code><a href="Control-Monad-State-Strict.html#v:runStateT">runStateT</a></code> (<code><a href="Control-Monad-State-Strict.html#v:mapStateT">mapStateT</a></code> f m) = f . <code><a href="Control-Monad-State-Strict.html#v:runStateT">runStateT</a></code> m</pre></li></ul></div></div><div class="top"><p class="src"><a id="v:withStateT" class="def">withStateT</a> :: (s -> s) -> <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m a -> <a href="Control-Monad-State-Strict.html#t:StateT">StateT</a> s m a <a href="#v:withStateT" class="selflink">#</a></p><div class="doc"><p><code><code><a href="Control-Monad-State-Strict.html#v:withStateT">withStateT</a></code> f m</code> executes action <code>m</code> on a state modified by
applying <code>f</code>.</p><ul><li><pre><code><a href="Control-Monad-State-Strict.html#v:withStateT">withStateT</a></code> f m = <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/transformers-0.5.2.0/Control-Monad-Trans-State-Strict.html#v:modify">modify</a></code> f >> m</pre></li></ul></div></div><div class="top"><p class="src">module <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Control-Monad.html">Control.Monad</a></p></div><div class="top"><p class="src">module <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Control-Monad-Fix.html">Control.Monad.Fix</a></p></div><div class="top"><p class="src">module <a href="Control-Monad-Trans.html">Control.Monad.Trans</a></p></div><h1 id="g:4">Examples</h1><div class="doc"><p>A function to increment a counter. Taken from the paper
<em>Generalising Monads to Arrows</em>, John
Hughes (<a href="http://www.math.chalmers.se/~rjmh/">http://www.math.chalmers.se/~rjmh/</a>), November 1998:</p><pre>tick :: State Int Int
tick = do n <- get
put (n+1)
return n</pre><p>Add one to the given number using the state monad:</p><pre>plusOne :: Int -> Int
plusOne n = execState tick n</pre><p>A contrived addition example. Works only with positive numbers:</p><pre>plus :: Int -> Int -> Int
plus n x = execState (sequence $ replicate n tick) x</pre><p>An example from <em>The Craft of Functional Programming</em>, Simon
Thompson (<a href="http://www.cs.kent.ac.uk/people/staff/sjt/">http://www.cs.kent.ac.uk/people/staff/sjt/</a>),
Addison-Wesley 1999: "Given an arbitrary tree, transform it to a
tree of integers in which the original elements are replaced by
natural numbers, starting from 0. The same element has to be
replaced by the same number at every occurrence, and when we meet
an as-yet-unvisited element we have to find a 'new' number to match
it with:"</p><pre>data Tree a = Nil | Node a (Tree a) (Tree a) deriving (Show, Eq)
type Table a = [a]</pre><pre>numberTree :: Eq a => Tree a -> State (Table a) (Tree Int)
numberTree Nil = return Nil
numberTree (Node x t1 t2)
= do num <- numberNode x
nt1 <- numberTree t1
nt2 <- numberTree t2
return (Node num nt1 nt2)
where
numberNode :: Eq a => a -> State (Table a) Int
numberNode x
= do table <- get
(newTable, newPos) <- return (nNode x table)
put newTable
return newPos
nNode:: (Eq a) => a -> Table a -> (Table a, Int)
nNode x table
= case (findIndexInList (== x) table) of
Nothing -> (table ++ [x], length table)
Just i -> (table, i)
findIndexInList :: (a -> Bool) -> [a] -> Maybe Int
findIndexInList = findIndexInListHelp 0
findIndexInListHelp _ _ [] = Nothing
findIndexInListHelp count f (h:t)
= if (f h)
then Just count
else findIndexInListHelp (count+1) f t</pre><p>numTree applies numberTree with an initial state:</p><pre>numTree :: (Eq a) => Tree a -> Tree Int
numTree t = evalState (numberTree t) []</pre><pre>testTree = Node "Zero" (Node "One" (Node "Two" Nil Nil) (Node "One" (Node "Zero" Nil Nil) Nil)) Nil
numTree testTree => Node 0 (Node 1 (Node 2 Nil Nil) (Node 1 (Node 0 Nil Nil) Nil)) Nil</pre><p>sumTree is a little helper function that does not use the State monad:</p><pre>sumTree :: (Num a) => Tree a -> a
sumTree Nil = 0
sumTree (Node e t1 t2) = e + (sumTree t1) + (sumTree t2)</pre></div></div></div><div id="footer"><p>Produced by <a href="http://www.haskell.org/haddock/">Haddock</a> version 2.17.2</p></div></body></html>
|