title: How can I update lists in SML using functions?
body: <p>I need to write an SML function that looks like this:</p>
  
  <pre><code>update(FLR, (x,y))
  </code></pre>
  
  <p>Where FLR is a finite list of tuples that looks like the following:</p>
  
  <pre><code>[(1,1),(2,4),(3,9),(4,16)]
  </code></pre>
  
  <p>But it can contain any number of tuples. What this update function needs to do is take in the list of tuples as the first argument and an x / y tuple as the second argument. If there is a tuple in the list that has the same x value as the one given to the function, it needs to update the y value of the list to the y value given to the function. If there is not a tuple with the x value given, the function needs to create a new tuple in the list at the appropriate location. For example, if the FLR has the values:</p>
  
  <pre><code>FLR = [(1,1),(2,4),(3,9),(4,16),(5,25)]
  </code></pre>
  
  <p>and the function is called as <code>update(FLR, (2,3));</code> The new list should be <code>[(1,1),(2,3),(3,9),(4,16),(5,25)]</code>. Also, if the function is called as <code>update(FLR, (6,36));</code> The new list should be <code>[(1,1),(2,4),(3,9),(4,16),(5,25), (6,36)]</code>.</p>
  
  <p>I am very new to functional programming and SML and I am not sure how to do this. I have written some memberOf functions that I'm sure I will need to use but my main concern is how to do all of this using recursion. Any help is greatly appreciated!</p>