Skip to content

Instantly share code, notes, and snippets.

@dhanji
Last active April 13, 2017 01:59
Show Gist options
  • Save dhanji/06f0a76ad0b2bfa5c9953e0e14e146ae to your computer and use it in GitHub Desktop.
Save dhanji/06f0a76ad0b2bfa5c9953e0e14e146ae to your computer and use it in GitHub Desktop.
-- Using merge to efficiently intersect two lists
ages = [1, 2, 5, 6]
names = [1, 5, 6, 7, 8, 9]
addresses = [2, 3, 7, 9, 10]
siblings = [3, 5, 6, 9]
intersect [] [] = []
intersect [] _ = []
intersect _ [] = []
intersect (x:xs) (y:ys)
| x == y = (x:intersect xs ys)
| x > y = intersect (x:xs) ys
| otherwise = intersect xs (y:ys)
main = putStrLn $ show $ intersect addresses siblings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment