Possible duplicate:
Replace individual list items in Haskell?
I managed to make some progress in this part of my assignment, but I added part of the code below:
module Grid where
data State = On | Off deriving (Eq, Show)
next :: State -> State
next On = Off
next Off = On
type Row = [State]
updateRow :: Row -> Int -> Row
updateRow (r:rs) x
| x == 0 = next r:rs
As shown in the last line just above, I was able to get updateRow to work when x = 0, as shown below (with the inverted 0th element).
*Grid> updateRow [Off,Off,Off,Off] 0
[On,Off,Off,Off]
*Grid>
All this disappears, however, when I try to invert other elements of this list. I cannot “decompose” the formula in this function.
I also MUST follow this convention like:
updateRow :: Row -> Int -> Row
Thanks in advance.
source
share