Skip to content

Instantly share code, notes, and snippets.

@ir4y
Created April 8, 2016 15:39
Show Gist options
  • Save ir4y/7474caf719d33461b78216a913ae7622 to your computer and use it in GitHub Desktop.
Save ir4y/7474caf719d33461b78216a913ae7622 to your computer and use it in GitHub Desktop.
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