title: Nested List Haskell Iteration
body: <p>I need to implement a nested list operation in Haskell.</p>
  
  <pre><code>f :: [[String]] -&gt; [[String]]
  </code></pre>
  
  <p>My input is a 2d array</p>
  
  <pre><code>[ [ ”A” , ”A” , ”A” ]  
  , [ ”B” , ”B” , ”A” ]
  , [ ”A” , ”A” , ”B” ] ]
  </code></pre>
  
  <p>I arbitrarily generated that list.</p>
  
  <pre><code>A A A
  B B A 
  A A B
  </code></pre>
  
  <p>So in my implementation I need to do the following.</p>
  
  <ul>
  <li>If a position has A, and it has 2 or more than 2 "B" neighbors, it will turn to B.</li>
  <li>If a position has B, and it has 2 or more than 2 "B" neighbors, it stays like as it is.</li>
  <li>If a position has B, and it has less than 2 "B" neighbors, it will turn to A.</li>
  </ul>
  
  <p>So after 1st step my table will look like this.</p>
  
  <pre><code>B B A
  A B B
  B B A
  </code></pre>
  
  <p>If I were going to use C or C++, my algorithm would like this:</p>
  
  <ol>
  <li><p>Make a copy of my input.</p></li>
  <li><p>Traverse both list in 2for loops, check if statements to make a change in the location and whenever I'm going to make a change, I will change the second list not the first, so that traversing the first list won't effect the other "A"'s and "B"'s.</p></li>
  <li><p>Return second list.</p></li>
  </ol>
  
  <p>The problem is, in Haskell, I cannot use iteration. How can I solve this problem?</p>