Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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