【发布时间】:2013-04-02 18:43:23
【问题描述】:
我有这段代码,但它并不能完全满足我的要求,我需要一个元组列表;
[(3,2),(1,2),(1,3),(1,2),(4,3),(3,2),(1,2)]
并给予
[(1,3),(4,3),(3,2),(1,2)]
但我希望它给予
[(1,3),(4,3)]
我哪里做错了?提前致谢。
eliminate :: [(Int,Int)] -> [(Int,Int)]
eliminate [] = []
eliminate (x:xs)
| isTheSame xs x = eliminate xs
| otherwise = x : eliminate xs
isTheSame :: [(Int,Int)] -> (Int,Int) -> Bool
isTheSame [] _ = False
isTheSame (x:xs) a
| (fst x) == (fst a) && (snd x) == (snd a) = True
| otherwise = isTheSame xs a
【问题讨论】:
-
“完全”是什么意思,为什么要排除
(3,2)和(1,2)? -
我正在寻找一个完全消除重复的函数,只有唯一的应该在那里,我想我应该改变我的实现:/