title: Real life and useful examples of Reverse State monad
body: <p><em>Reverse State monad</em> is really nice and mind blowing example of Haskell language's expressiveness and lazy evaluation. But it's not that easy to understand this monad. Moreover, it's really hard to find some convincing real life example of what you can do with <em>Reverse State monad</em> easier than with any other tool in the language.</p>
  
  <p><em>Reverse State</em> monad is defined in the next way:</p>
  
  <pre><code>newtype RState s a = RState { runRState :: s -&gt; (a,s) }
  
  instance Monad (RState s) where
      return x = RState $ (,) x
      RState sf &gt;&gt;= f = RState $ \s -&gt;
          let (a, past)   = sf future
              (b, future) = runRState (f a) s
          in (b, past)
  </code></pre>
  
  <p>It already has some examples and usages but I don't find them quite practical.</p>
  
  <ol>
  <li><a href="https://www.quora.com/What-are-some-crazy-things-one-can-do-with-monads-in-Haskell" rel="noreferrer">Quora answer</a>: well-explained and even has real life example of usage but without code and it's not clear whether it's a really good idea to use <code>RState</code>.</li>
  <li><a href="https://lukepalmer.wordpress.com/2008/08/10/mindfuck-the-reverse-state-monad/" rel="noreferrer">Mindfuck</a>: introducing this nice concept but example is not useful. Nobody will write Fibonacci numbers this way.</li>
  <li><a href="https://kseo.github.io/posts/2017-01-21-writer-monad.html" rel="noreferrer">Kwang's Haskell Blog</a>: shows how <code>Writer</code> can be emulated with <code>RState</code> but come on. Not really a real life example :)</li>
  </ol>
  
  <p>I'm also aware of <a href="https://hackage.haskell.org/package/tardis-0.3.0.0/docs/Control-Monad-Tardis.html" rel="noreferrer"><code>tardis</code></a> package but no tutorial of this library, documentation examples are really abstract, not so many people really understand it. The closest to what I want is <a href="http://kcsongor.github.io/time-travel-in-haskell-for-dummies/" rel="noreferrer">this tutorial</a> but it has example of <code>tardis</code>, not just <code>RState</code>. As well as <a href="https://books.google.ru/books?id=IZsQAwAAQBAJ&amp;pg=PA391&amp;lpg=PA391&amp;dq=haskell%20tardis%20package&amp;source=bl&amp;ots=Dqte9JG-un&amp;sig=Udct1ZqCjfxz1b8u8D0sSkKrhaM&amp;hl=ru&amp;sa=X&amp;ved=0ahUKEwjh_rLAps3TAhVCP5oKHSCkAEgQ6AEIXTAH#v=onepage&amp;q=haskell%20tardis%20package&amp;f=false" rel="noreferrer">this book reference</a>.</p>
  
  <p>Thus I'm not looking for <code>tardis</code> real life patterns, I'm interested only in <code>RState</code> illustration if possible. Though I understand that there might be no samples of pure <code>RState</code> usages. In that case minimal example with <code>RStateT</code> transformer or <code>tardis</code> is good enough.</p>
  
  <p>Did someone use this monad in real life or have really nice &amp; useful illustration with code?</p>