Skip to content

Instantly share code, notes, and snippets.

@thomas-mcdonald
Created January 13, 2013 21:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomas-mcdonald/4526231 to your computer and use it in GitHub Desktop.
Save thomas-mcdonald/4526231 to your computer and use it in GitHub Desktop.
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