I have a list with elements that are tuples example:
[(1,2),(3,9),(7,9),(6,4),(1,2),(4,2),(3,9),(1,2)]
I need to compare the first element with the rest of the elements, then then the second item with the rest of the list and so on to return the repeated elements
In this case it should return
(1,2),(1,2),(1,2),(3,9),(3,9)
any idea how to implement it?
I have this implemented
test :: Eq a => [(a,a)] -> [(a,a)]
test [(x,y)] = [(x,y)]
test (x:y:xs)
|((fst (x) == fst (y)) && (snd (x) == snd (y))) = ( [y]) ++ (test (x:xs) )
|otherwise = test (x:xs)
the end condition is bad and always returns the last element of the list
test [(x,y)] = [(x,y)]
And it only compares the first item with the rest of the list but I need to compare the second, the third ... with the rest of the list