My explanation in the title might have been fairly bad, but the problem I'm having is this:
shared [[10,5,10,10,7,10],[2,6,10,10]]
output: [10,10,10,10]
I want the output to be [10,10].
I'm trying to write a variation of Data.List.intersect which is unbiased with respect with the order of the arguments. Each value should appear in the result the same number of times in whichever list it occurs fewer times. (In contrast, with Data.List.intersect if a value shows up in the result the amount of occurrences of it will be the same as in the first list.)
My current attempt is:
import Data.List
myintersect :: Eq a => [a] -> [a] -> [a]
myintersect [] _ = []
myintersect (x:xs) ys
| x `elem` ys = x : myintersect xs ys
| otherwise = myintersect xs ys
shared :: (Eq a) => [[a]] -> [a]
shared x = foldr1 myintersect x
It doesn't work correctly, though. shared [[10,5,10,10,7,10],[2,6,10,10]] is [10,10,10,10], rather than [10,10].
I've been looking into using zip, but that fails to work with different length lists.