m1 = [2, 4, 5, 7, 8, 9, 12, 13, 20, 0] :: [Int]
m2 = [2, 4, 5, 21, 23, 24, 7, 8, 9, 12, 13, 31, 32, 33, 20, 0] :: [Int]
main = do
let mss = comps m1 m2
mapM_ print mss
comps :: (Eq a) => [a] -> [a] -> [[a]]
comps xs' ys' = reverse $ comps' xs' ys' [] True
where
comps' [] __ zs _ = zs
comps' __ [] zs _ = zs
comps' (x:xs) (y:ys) zs True | x == y = comps' xs ys zs True
comps' (x:xs) (y:ys) zs True | x /= y = comps' (x:xs) ys ( [y] :zs) False
comps' (x:xs) (y:ys) (z:zs) False | x /= y = comps' (x:xs) ys ((y:z):zs) False
comps' (x:xs) (y:ys) (z:zs) False | x == y = comps' xs ys ( z' :zs) True
where z' = reverse z
Main> :main
[21,23,24]
[31,32,33]