从Haskell中的字符串中删除字符

从Haskell中的字符串中删除字符,haskell,Haskell,我正在创建一个程序,它读取一个文本文件,将单词拆分并存储在列表中。我一直在尝试创建一个函数,该函数接收一个字符串,该字符串是文件中的整个文本字符串,并删除标点符号,例如“;”,“,”,“,”,但不幸的是,还没有任何运气。该程序在没有标点符号功能的情况下工作,但当我将其包含到(ToWord文件内容)中时就不能工作。请有人看看我做了什么,看看我做错了什么 以下是我目前掌握的代码: main = do contents <- readFile "LargeTextFile.tx

我正在创建一个程序,它读取一个文本文件,将单词拆分并存储在列表中。我一直在尝试创建一个函数,该函数接收一个字符串,该字符串是文件中的整个文本字符串,并删除标点符号,例如“;”,“,”,“,”,但不幸的是,还没有任何运气。该程序在没有标点符号功能的情况下工作,但当我将其包含到
(ToWord文件内容)
中时就不能工作。请有人看看我做了什么,看看我做错了什么

以下是我目前掌握的代码:

main = do  
       contents <- readFile "LargeTextFile.txt"
       let lowContents = map toLower contents
       let outStr = countWords (lowContents)
       let finalStr = sortOccurrences (outStr)
       let reversedStr = reverse finalStr
       putStrLn "Word | Occurrence "
       mapM_ (printList) reversedStr

-- Counts all the words.
countWords :: String -> [(String, Int)]
countWords fileContents = countOccurrences (toWords (removePunc fileContents))

-- Splits words and removes linking words.
toWords :: String -> [String]
toWords s = filter (\w -> w `notElem` ["an","the","for"]) (words s)

-- Remove punctuation from text String.
removePunc :: String -> String
removePunc xs = x | x <- xs, not (x `elem` ",.?!-:;\"\'")

-- Counts, how often each string in the given list appears.
countOccurrences :: [String] -> [(String, Int)]
countOccurrences xs = map (\xs -> (head xs, length xs)) . group . sort $ xs

-- Sort list in order of occurrences.
sortOccurrences :: [(String, Int)] -> [(String, Int)]
sortOccurrences sort = sortBy (comparing snd) sort

-- Prints the list in a format.
printList a = putStrLn((fst a) ++ " | " ++ (show $ snd a))
main=do
内容[(字符串,Int)]
countWords fileContents=countexecutions(toWords(removePunc fileContents))
--拆分单词并删除链接单词。
toWords::String->[String]
toWords=filter(\w->w`notElem`[“an”,“the”,“for”])(单词s)
--从文本字符串中删除标点符号。
removePunc::String->String
removePunc xs=x | x您可能需要:

removePunc xs = [ x | x <- xs, not (x `elem` ",.?!-:;\"\'") ]

removePunc xs=[x | x另一个选项是只使用
filter(而不是('elem`,.?!-:;\“\”))xs
这很有效谢谢!我只是缺少方括号。另一个选项是对@bheklillr的答案的修改:
filter('notElem`,.?!-:;\“\”))xs