haskell:删除列表中的特定字符串

时间:2017-03-16 20:42:27

标签: string haskell

我写了这个函数来删除列表中以'{'开头并以'}'结尾的任何单词:

delete []=[]
delete c@(x:xs) | head x=='{' && last x=='}'= rep x " " (unwords c)
                | otherwise = delete xs 

我正在使用辅助函数rep:

rep _ _ [] = []
rep a b s@(x:xs)= if isPrefixOf a s
              then b++rep a b (drop(length a)s)
              else x: rep a b xs

当我在下面的字符串列表上调用删除函数时,它会成功删除第一个字符串“author”,但留下另外两个“reference”,“title”:

[“{author}”,“has”,“声明”,“that”,“{reference}”,“{title}”,“has”,“已”,“已发布”,“...... “]

请告诉我,我的功能中缺少?

谢谢,

奥马

0 个答案:

没有答案