好吧,这可能会出现在前奏中,但是:有没有标准的库函数来查找列表中的唯一元素?我的(重新)实施,澄清,是:
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
Run Code Online (Sandbox Code Playgroud)