title: One more time...can I have an example of state monad that does what I want?
body: <p>I'm trying to understand the actual need for the reader and/or state monads. All the examples I've seen (including many on stackoverflow as I've hunted for suitable examples I can use and in various books and blog articles) are of the form (pseudo code)</p>
  
  <pre><code> f = do
          foo &lt;- ask
          do something with foo
  
   g = do
          foo &lt;- ask
          do something else using foo
  
   h = runReader
         (
             f
             g
         )
  </code></pre>
  
  <p>In other words, call two functions and (presumably) maintain some state from one call to the next. However, I don't find this example particularly convincing as (I think) I could just have f return some state and then pass that state on to g.</p>
  
  <p>I'd love to see an example, using a single integer (say) as the state to be preserved where, rather than two sequential calls to f and then g from a central place, rather there's a call to f which then internally calls g and then have changed state (if state monad) available back in the main routine.</p>
  
  <p>Most (well actually all) the examples I have seen spend a tremendous amount of time focusing on the definition of the monad and then show how to set up a single function call. To me, it would be the ability to do nested calls and have the state carried along for the ride to demonstrate why it's useful.</p>