2

My problem is I have a list and want to remove some strings in it. but when I remove the first time it's OK. but the second time, it removes the string but bring back the first one. do you know how I can avoid this? thank you

Prelude Data.List Data.Char> x = ["ab","cd","ef","gh"]

Prelude Data.List Data.Char> delete "ab" x

["cd","ef","gh"]

Prelude Data.List Data.Char> delete "cd" x

["ab","ef","gh"]

!!Here the "ab" came back and I don't want this!! thanks

Will Ness
  • 70,110
  • 9
  • 98
  • 181
Bilal
  • 53
  • 4

1 Answers1

5

See ''How to "think functional"'' here. In short, x is the same x; delete "abc" x returns new value, it does not change the existing x.

If you want to refer to this new value, give it a new name, like this:

> x = ["ab","cd","ef","gh"]

> x2 = delete "ab" x

> delete "cd" x2
["ef","gh"]
Will Ness
  • 70,110
  • 9
  • 98
  • 181
  • thank you. Yh, I've done this but you can't using this techniques with a string of 100 elements. – Bilal Feb 12 '22 at 17:16
  • 1
    a. yes you can. b. you can instead create a _list_ of subsequent values. see the linked answer. :) if in doubt, do ask about it, with concrete specific details please. – Will Ness Feb 12 '22 at 17:17