Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设我有元组列表,例如
[(1,2),(2,1),(3,5)]
我将如何定义一个函数,以便删除具有相似元素但顺序不同的元组?所以列表变成了
[(1,2),(3,5)]
与相等函数一起使用nubBy,该函数将两个元组与交换或未交换的相等元素进行比较。该swap功能使这更容易:
nubBy
swap
nubSwapped :: (Eq a) => [(a, a)] -> [(a, a)] nubSwapped = nubBy $ \a b -> a == b || swap a == b