3
Hello, it’s been a few hours that I’m trying to make a function in Haskell that gives two lists and returns a new list
Where this new list is the union of the other two lists but without repetitions , that is, a list [1,2,3][3,2,1] should return [1,2,3] or a list [10,20,30][90,80,30] should return [10,20,30,90,80] (see that 30 is on both lists, so it should not be on the list)
What I have is this :
uniaoS :: [Int] -> [Int] -> [Int]
uniaoS [] [] =[]
uniaoS [] (x:xs) =(x:xs)
uniaoS (x:xs) [] =(x:xs)
uniaoS(a:as)(x:xs)
| (a == x) = uniaoS as xs
| otherwise = a:as ++ x:xs
In this case it is returning the list minus the repetitions , ie [1,2,3] [1,2,4] returns [3,4], but I would also like you to return the repeated elements [1,2,3,4]
Thank you very much
– Hugo