HASKELL --- 是否有删除列表中元素的函数?

HASKELL --- Is there any function to remove an element in a list?

我的问题是我有一个列表,想删除其中的一些字符串。但是当我第一次删除时就可以了。但是第二次,它删除了字符串但带回了第一个。 你知道我怎样才能避免这种情况吗? 谢谢

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"]

!!这里 "ab" 回来了,我不想要这个!!谢谢

参见 ''How to "think functional"'' here。总之,x就是xdelete "abc" x returns 值,它不会改变现有的x.

如果你想引用这个新的值,给它一个新的名字,像这样:

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

> x2 = delete "ab" x

> delete "cd" x2
["ef","gh"]