好吧,这可能是前奏,但是:是否有一个标准库函数可以查找列表中的唯一元素?为了澄清起见,我的(重新)实现是:
has :: (Eq a) => [a] -> a -> Bool
has [] _ = False
has (x:xs) a
| x == a = True
| otherwise = has xs a
unique :: (Eq a) => [a] -> [a]
unique [] = []
unique (x:xs)
| has xs x = unique xs
| otherwise = x : unique xs
最佳答案
关于list - haskell 列表中的唯一元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3098391/