title: updating a associated list in Haskell
body: <p>I have a simple set of states like this:</p>
  
  <pre><code>st1 = [("x", 2), ("y", 3), ("z", 3)]
  </code></pre>
  
  <p>I want to update this as the program runs since the values will change. I have an update code like this:</p>
  
  <pre><code>update str val st = (str, val) : foldr step [] st where
      step x acc
          | fst x == str = acc
          | otherwise = x:acc
  </code></pre>
  
  <p>I want to make an assign function that is like this:</p>
  
  <pre><code>assign (str, val) env = update str val env
  </code></pre>
  
  <p>The problem I am having is that since Haskell has no side effects my updated list does not stay updated. Any ideas or suggestions on how to do this? </p>
  
  <p>If I type in the interpreter if I do</p>
  
  <pre><code>let st2 = update "x" 1 st1
  </code></pre>
  
  <p>Then the new state is saved.</p>
  
  <p>I want the function to do this:</p>
  
  <pre><code>update "x"  1 st1
  
  Before:   [("x",1),("y",3),("z",3)]
  
  After:    [("y",1),("x",2),("z",3)]
  </code></pre>