Replace individual list elements in Haskell?

后端 未结 9 686
死守一世寂寞
死守一世寂寞 2020-12-01 12:02

I have a list of elements and I wish to update them:

from this: [\"Off\",\"Off\",\"Off\",\"Off\"]

to this: [\"Off\",\"Off\",\"On\",\"Off\

9条回答
  •  感情败类
    2020-12-01 12:45

    I think you should consider using a data structure other than List. For example, if you just want to have a state of four on/off switches then:

    data State = St { sw1, sw2, sw3, sw4 :: Bool }
    

    For a dynamic number of switches then consider a mapping from switch name to Bool.

提交回复
热议问题