As I could not use Data.MultiSet
I needed to imeplement my own solution via lists, so I will post the solution.
In order to get the set difference of two lists with repetitons, we first need to group the numbers together, to get the amount of repetitions of each number:
tupleGroup [] _ = []
tupleGroup (hd:tl) (x, y)
| hd == x = (x, succ y) : tupleGroup tl (x, succ y)
| otherwise = (hd, 1) : tupleGroup tl (hd, 1)
group' [] = []
group' (hd:tl) = tupleGroup tl (hd, 1)
In order to call the helper function group' we first need to sort the list, as tupleGroup needs a sorted list.
Next function is the difference function, in which we supply the grouped lists:
difference [] [] = []
difference (hd:tl) [] = fst hd : difference tl []
difference [] (hd:tl) = []
difference (hd1:tl1) (hd2:tl2)
| x1 == x2 && y1 > y2 = x1 : difference tl1 tl2
| x1 == x2 = difference tl1 tl2
| x1 < x2 = x1 : difference tl1 (hd2:tl2)
| otherwise = difference (hd1:tl1) tl2
where
x1 = fst hd1
x2 = fst hd2
y1 = snd hd1
y2 = snd hd2
The function will return a list of all numbers, which the repetition count is bigger in the first list, than in the second one.