标签: haskell
假设我在GHCI中声明了一个变量
let a = ["hello","goodbye","","sup","bye","hi","cat","dog"]
我想从列表中删除那个讨厌的“”。根据我的理解,我应该能够使用dropWhile这样做,就像这样
dropWhile null a
但这并没有消除讨厌的“”。为什么是这样?我该如何解决这个问题?
答案 0 :(得分:9)
True
dropWhile会删除元素。 null "hello"是False,因此,它应该放弃任何东西。
dropWhile
null "hello"
False
您可能正在寻找filter:
filter
Prelude> filter (not . null) ["hello","goodbye","","sup","bye","hi","cat","dog"] ["hello","goodbye","sup","bye","hi","cat","dog"]