Created
March 5, 2016 13:16
-
-
Save blitzcode/9d96be6eaea7dfd62742 to your computer and use it in GitHub Desktop.
Haskell Bin Tree to List
This file contains hidden or 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
module Main where | |
data Tree a = Empty | Node a (Tree a) (Tree a) | |
tree :: Tree Int | |
tree = Node 4 (Node 2 (Node 1 Empty Empty) (Node 3 Empty Empty)) (Node 6 (Node 5 Empty Empty) (Node 7 Empty Empty)) | |
toList :: Tree a -> [a] | |
toList root = go root [] | |
where go :: Tree a -> [a] -> [a] | |
go Empty xs = xs | |
go (Node v l r) xs = go l $ v : go r xs | |
main :: IO () | |
main = do | |
print $ toList tree |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment