Created
September 22, 2010 13:00
-
-
Save bavardage/591616 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
data Tree a = Node a | Bend a (Tree a) | Branch a (Tree a) (Tree a) deriving Show | |
label :: Tree a -> Tree Int | |
label = undefined | |
labelfrom :: Int -> Tree a -> (Tree Int, Int) | |
labelfrom i (Node a) = (Node (i+1), i+1) | |
labelfrom i (Bend a t) = (Bend (j+1) lt, j+1) | |
where | |
(lt, j) = labelfrom i t | |
labelfrom i (Branch a t1 t2) = (Branch (j2+1) lt1 lt2, j2+1) | |
where | |
(lt1, j1) = labelfrom i t1 | |
(lt2, j2) = labelfrom j1 t2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment