Skip to content

Instantly share code, notes, and snippets.

@bavardage
Created September 22, 2010 13:00
Show Gist options
  • Save bavardage/591616 to your computer and use it in GitHub Desktop.
Save bavardage/591616 to your computer and use it in GitHub Desktop.
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