Created
January 19, 2011 07:44
-
-
Save sumerman/785834 to your computer and use it in GitHub Desktop.
Test Pastie
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 BiTree a = Leaf a | BiTree a (BiTree a) (BiTree a) deriving Show | |
{-flatten :: BiTree a -> [a]-} | |
{-flatten (BiTree v l r)= [v] ++ flatten l ++ flatten r-} | |
{-flatten (Leaf v) = [v]-} | |
flatten' :: BiTree a -> [a] -> [a] | |
flatten' (Leaf v) res = v:res | |
flatten' (BiTree v l r) res = v:flatten' l (flatten' r res) | |
flatten :: BiTree a -> [a] | |
flatten t = flatten' t [] | |
t = (BiTree 0.5 (Leaf 1.0) (BiTree 0.2 (Leaf 2.0) (Leaf 3.0))) | |
main = putStrLn ( "Tree: " ++ show t ) >> putStrLn ( "Flattened: " ++ show (flatten t) ) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment