Last active
December 24, 2015 17:59
-
-
Save AKST/6839991 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data Tree a = Node a (Tree a) (Tree a) | Empty | |
tFilter :: (Ord a) => (a -> Bool) -> Tree a -> Tree a | |
tFilter f tree = impl f tree Empty | |
where | |
impl f Empty acc = acc | |
impl f (Node x l r) acc = | |
impl f l $ | |
impl f r $ | |
if f x | |
then incl x acc | |
else acc | |
incl :: Ord a => a -> Tree a -> Tree a | |
incl x Empty = Node x Empty Empty | |
incl x t@(Node y l r) | |
| x < y = Node y (incl x l) r | |
| x > y = Node y l (incl x r) | |
| otherwise = t |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment