title: Haskell ReaderT Design Pattern vs mtl StateT pattern
body: <p>I'm designing a small game which basically uses StateT and just updating the state. Below is the simplified version:</p>
  
  <pre><code>{-# LANGUAGE TemplateHaskell #-}
  
  import           Control.Lens
  import           Control.Monad
  import           Control.Monad.IO.Class
  import           Control.Monad.State
  import           Control.Monad.State.Class
  import           System.Random
  
  data PlayerState = PlayerState {
    _psName  :: String,
    _psScore :: Int
                                 } deriving (Show)
  
  makeClassy ''PlayerState
  
  data Game = Game {
    _turns   :: Int,
    _players :: [PlayerState]
                   } deriving (Show)
  
  makeClassy ''Game
  
  randomGameInit :: IO Game
  randomGameInit = do
    players &lt;- replicateM 5 $  PlayerState &lt;$&gt; (replicateM 4 $ randomRIO ('a', 'z')) &lt;*&gt; randomRIO (1,10)
    return $ Game 0 players
  
  update :: (MonadState s m, HasGame s) =&gt; m ()
  update = do
    players . ix 0 . psName %= (\_ -&gt; "mordor")
    turns %= (+1)
    exitCondition &lt;- fmap (&gt;10) (turns &lt;%= id)
    unless exitCondition update
  
  main :: IO ()
  main = do
    init &lt;- randomGameInit
    runStateT update init &gt;&gt; print "Game Over"
  </code></pre>
  
  <p>I've recently learned about the <a href="https://www.fpcomplete.com/blog/2017/06/readert-design-pattern" rel="noreferrer">ReaderT Design Pattern vs mtl StateT</a>, which encourages replacing <code>StateT</code> with a mutable reference inside a <code>ReaderT</code> over <code>IO</code>.</p>
  
  <p>I wonder how I should adapt the code using ReaderT. Most specifically, many <code>Lens</code> functions have types: <code>(MonadState s m)</code> which apparently need to be inside a State. Does this mean that <code>Lens</code> library functions are designed for StateT and not ReaderT?  How to use <code>Lens</code> with <code>ReaderT</code> design pattern?</p>