Created
April 8, 2016 15:39
-
-
Save ir4y/7474caf719d33461b78216a913ae7622 to your computer and use it in GitHub Desktop.
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
markTree :: Tree () -> State Integer (Tree Integer) | |
markTree (Leaf _) = do | |
n <- get | |
put (n+1) | |
return (Leaf n) | |
markTree (Fork l _ r) = do | |
l' <- markTree l | |
n <- get | |
put (n+1) | |
r' <- markTree r | |
return (Fork l' n r') | |
numberTree :: Tree () -> Tree Integer | |
numberTree tree = evalState (markTree tree) 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment