I am trying to create functions which can find the union and intersection of two multi sets in Haskell without the use of the Multiset module. I have a good understanding of basic intersections and unions in normal lists but multisets seem to throw me. So far for the intersect function I have:
setUnique :: (Eq a) => [a] -> [a]
setUnique [] = []
setUnique (x:xs)
| elem x xs = setUnique xs
| otherwise = x : setUnique xs
setIntersect' :: (Eq a) => [a] -> [a]
setIntersect' xs ys = setUnique (xs ++ ys)
The issue I have in the above code is that I am actually getting values that aren't a part of the intersect. eg [1,2,2,3,3,3] [1,2,2] = [3,1,2]