title: How do I avoid referring to all state variables when updating only a few?
body: <p>An idiom I use for composing a couple of procedures (with memory) is as follows:</p>
  
  <pre><code>p1 :: State (Int, String) ()
  p1 = do
      (a, b) &lt;- get
      ... do something ...
      put (a', b)
  
  p2 :: State (Int, String) ()
  p2 = do
      (a, b) &lt;- get
      ... do something else ...
      put (a, b')
  
  main = do
      ... initializing a0 b0 ...
      print . flip evalState (a0, b0)
            . sequence $ replicate 10 p1 ++ repeat p2
  </code></pre>
  
  <p>However, as the number of state variable grows, this quickly gets way more verbose than necessary: </p>
  
  <pre><code>p1 :: State (Int, String, Bool, Int, String, Bool) ()
  p1 = do
      (a, b, c, d, e, f) &lt;- get
      ... do something ...
      put (a, b, c', d, e, f')
  
  p2 :: State (Int, String, Bool, Int, String, Bool) ()
  p2 = do
      (a, b, c, d, e, f) &lt;- get
      ... do something ...
      put (a', b', c, d, e, f)
  
  main = do
      print . flip evalState (a0, b0, c0, d0, e0, f0)
            . sequence $ replicate 10 p1 ++ repeat p2
  </code></pre>
  
  <p>As I was wondering, is there a way of updating only a few state variables without having to refer to all the unused ones? I was thinking something like <code>IORef</code> but for <code>State</code> (in fact there is a package <a href="https://hackage.haskell.org/package/stateref" rel="noreferrer">stateref</a>), but I'm not sure if there are already some common idioms that other people have been using.</p>