I have a list of elements and I wish to update them:
from this: ["Off","Off","Off","Off"]
to this: ["Off","Off","On","Off"]
As I am somewhat new to Haskell, I have been using (x:xs)!!y
to extract and update individual components using the function:
replace y z [] = []
replace y z (x:xs)
| x==y = z:replace y z xs
| otherwise = x:replace y z xs
and then entering the following in ghci: (replace "Off" "On" ["Off",'Off","Off","Off"]) !! 2
I get the following: "On"
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.
Any help regarding this matter would be appreciated.
See Question&Answers more detail:os