Created
September 16, 2018 18:49
-
-
Save TomasDrozdik/5af0562e252b7adf50f1cc8bbfca95ea to your computer and use it in GitHub Desktop.
This file contains hidden or 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
data Tree a = Tree a [Tree a] deriving Show | |
label :: Tree a -> Tree (a, Int) | |
label t = label' 1 t | |
label' :: Int -> Tree a -> Tree (a, Int) | |
label' i (Tree x []) = Tree (x, i) [] | |
label' i (Tree x ts) = | |
let | |
processed = goThrough i ts | |
Tree (y, label) list = last processed | |
in | |
Tree (x, label+1) processed | |
goThrough :: Int -> [Tree a] -> [Tree (a, Int)] | |
goThrough _ [] = [] | |
goThrough i (t:ts) = | |
let | |
Tree (val, label) list = label' i t | |
in | |
[Tree (val, label) list] ++ goThrough (label+1) ts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment