Replace individual list elements in Haskell?

后端 未结 9 664
死守一世寂寞
死守一世寂寞 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:41

    Here is a one liner that works perfectly

    replace pos newVal list = take pos list ++ newVal : drop (pos+1) list
    

    I doesn't seem efficient to do this kind of things in haskell.

提交回复
热议问题