[Haskell-beginners] removing duplicate tuples (including symmetrical ones)

Martin Tomko martin.tomko at geo.uzh.ch
Tue Sep 28 05:33:54 EDT 2010

Hi all,
I apologize for spamming this forum so frequently, but there is noone I 
can turn to around here...
I have a list of (a,a) tuples, and am trying something like nub, but 
also matching for symmetrical tuples. I implemented it using the 
template from delete from Prelude. Seems like my typse signature has 
some troubles (Paarse error in pattern) but I am not sure where the 
problem is.

removeDuplTuples :: [(a,a)] -> [(a,a)]
removeDuplTuples [] = []
removeDuplTuples [b] = [b]                                             
                 -- using the syntactic sugar for single element in list
removeDuplTuples x:xs = nub (if elem (snd x,fst x) xs then 
removeDuplTuples xs else [x] ++ removeDuplTuples xs)

I assume the problem lies in elem (snd x,fst x) xs but I am not sure how 
to rewrite it.

Thanks for all help,

More information about the Beginners mailing list