Skip to content

Instantly share code, notes, and snippets.

@deque-blog
Last active December 26, 2016 13:44
Show Gist options
  • Save deque-blog/eb424ce3f773ff3e5979f3815af871b1 to your computer and use it in GitHub Desktop.
Save deque-blog/eb424ce3f773ff3e5979f3815af871b1 to your computer and use it in GitHub Desktop.
treeWalkC :: Tree a -> [a]
treeWalkC EmptyTree = []
treeWalkC (Tree root) = treeWalkC' root
treeWalkC' :: Node a -> [a]
treeWalkC' n = loop n id
where
loop (Node v cs) cont = loopChildren cs (cont . (v:))
loopChildren [] cont = cont []
loopChildren (c:cs) cont =
loop c $ \res -> loopChildren cs (cont . (res ++))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment