Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
union lol
union [] [] = []
union [] ys = ys
union xs [] = xs
union (x@(n,_):xs) ys
| has n ys = (join x (find n ys)):(union xs (without n ys))
| otherwise = x:(union xs ys)
where
find p = filter (\x -> fst x == p)
without p = filter (\x -> fst x != p)
has p = length (find p) != 0
join (n,x) (_,y) = (n,x+y)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment