Skip to content

Instantly share code, notes, and snippets.

@jutememo
Created May 3, 2011 06:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jutememo/952890 to your computer and use it in GitHub Desktop.
Save jutememo/952890 to your computer and use it in GitHub Desktop.
data Tree a = Leaf a | Branch (Tree a) (Tree a) deriving Show
t = Branch
(Branch
(Leaf 1)
(Leaf 2))
(Branch
(Leaf 3)
(Branch
(Leaf 4)
(Leaf 5)))
leafCount (Leaf _) = 1
leafCount (Branch l r) = leafCount l + leafCount r
leafCount_cps (Leaf _) k = k 1
leafCount_cps (Branch l r) k = leafCount_cps l $ \x ->
leafCount_cps r $ \y ->
k $ x + y
main = do print $ leafCount t
print $ leafCount_cps t (\x -> x)
leafCount_cps t print
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment