我是Haskell的新手,想要解決我的問題的一些方向。我想有一個文本編碼功能,列出文本中的每個單詞由其索引表示。對於例如:Haskell文本編碼器
["The more I like, the more I love.","The more I love, the more I hate."]
輸出可能是
(["The", "more", "I", "like", "the", "love.", "love,", "hate."],
[1, 2, 3, 4, 5, 2, 3, 6, 1, 2, 3, 7, 1, 2, 3, 8])
我也做了消除重複部分
removeDuplicates :: Eq a => [a] -> [a]
removeDuplicates = rdHelper []
where rdHelper seen [] = seen
rdHelper seen (x:xs)
| x `elem` seen = rdHelper seen xs
| otherwise = rdHelper (seen ++ [x]) xs
爲什麼你用'逗號',用逗號,但是''''沒有逗號,儘管'like'在句子中逗號? –