%% toListPlus(x,r) = toList(x) ++ r. Define case toListPlus(leaf(n), r) = n::r case toListPlus(nonleaf(x,y), r) = toList(x, toList(y, r)) %Define Define toList(t) = toListPlus(t, []).
You can always have helper functions.