Skip to content

Instantly share code, notes, and snippets.

@tim-br
Created August 2, 2015 17:40
Show Gist options
  • Save tim-br/c22ff689c865f11cc67c to your computer and use it in GitHub Desktop.
Save tim-br/c22ff689c865f11cc67c to your computer and use it in GitHub Desktop.
set functions from sicp for haskell
intersection_set _ [] = []
intersection_set [] _ = []
intersection_set (x:xs) ys
| element_of_set x ys = x : intersection_set xs ys
| otherwise = intersection_set xs ys
element_of_set _ [] = False
element_of_set x (y:ys)
| x == y = True
| otherwise = element_of_set x ys
adjoin_set x ys
| element_of_set x ys = ys
| otherwise = x : ys
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment