Ask yourself, how many a values can your tree hold? They appear either in leaves or nodes,
data Tree a = Leaf a | Branch a (Tree a) (Tree a)
so
num_values = 1 | ( 1 + num_values + num_values )
It doesn't make much sense in this form, so let's write it as
numvals = 1 : [ 1 + s | s <- diagonalize
[ [ n + m | m <- numvals ]
| n <- numvals ] ]
diagonalize :: [[a]] -> [a]
diagonalize ((n:ns):t) = n:go [ns] t
where
go as (b:bs) = map head as ++ go (b:map tail as) bs
so that we get
~> take 100 numvals
[1,3,5,5,7,7,7,7,7,9,9,9,9,9,11,9,9,9,11,11,11,11,9,9,11,13,11,13,11,9,9,11,13,1
3,13,13,11,9,9,11,13,13,15,13,13,11,11,11,11,13,13,15,15,13,13,11,11,11,13,13,13
,15,15,15,13,13,13,11,11,13,15,13,15,15,15,15,13,15,13,11,11,13,15,15,15,15,15,1
5,15,15,15,13,11,11,13,15,15,17,15,15]
but you want 0, 2, 4, ... to appear there as well.
edit:
It is easy to fix this, with
data Tree a = Leaf | Branch a (Tree a) (Tree a)
Now
numvals2 = 0 : [ 1 + s | s <- diagonalize
[ [ n + m | m <- numvals2 ]
| n <- numvals2 ] ]
and
~> take 100 numvals2
[0,1,2,2,3,3,3,3,3,4,4,4,4,4,5,4,4,4,5,5,5,5,4,4,5,6,5,6,5,4,4,5,6,6,6,6,5,4,4,5
,6,6,7,6,6,5,5,5,5,6,6,7,7,6,6,5,5,5,6,6,6,7,7,7,6,6,6,5,5,6,7,6,7,7,7,7,6,7,6,5
,5,6,7,7,7,7,7,7,7,7,7,6,5,5,6,7,7,8,7,7]
Treedoes not allow emptyTree, therefore, you cannot generate aTreethat is a list in disguise, akaBranch 1 Leaf (Branch 2 Leaf (Branch 3 Leaf)). That being said, I'm not really sure what you're asking about.Branch 1 Leaf (Branch 2 Leaf (Branch 3 Leaf Leaf)). this is not to nitpick, of course, but for the benefit of a casual reader.