Skip to content

Instantly share code, notes, and snippets.

@sumerman
Created January 19, 2011 07:44
Show Gist options
  • Save sumerman/785834 to your computer and use it in GitHub Desktop.
Save sumerman/785834 to your computer and use it in GitHub Desktop.
Test Pastie
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