title: Replace individual list elements in Haskell?
body: <p>I have a list of elements and I wish to update them:</p>
  
  <p>from this: <code>["Off","Off","Off","Off"]</code></p>
  
  <p>to this:  <code>["Off","Off","On","Off"]</code></p>
  
  <p>As I am somewhat new to Haskell, I have been using <code>(x:xs)!!y</code> to extract and update individual components using the function:</p>
  
  <pre><code>replace y z [] = []
  replace y z (x:xs)
    | x==y           = z:replace y z xs
    | otherwise      = x:replace y z xs
  </code></pre>
  
  <p>and then entering the following in ghci: <code>(replace "Off" "On" ["Off",'Off","Off","Off"]) !! 2</code></p>
  
  <p>I get the following: <code>"On"</code></p>
  
  <p>I seem to be able to extract and convert elements of a list but I can't seem to get a list up with the single element converted.</p>
  
  <p>Any help regarding this matter would be appreciated.</p>