4 ms·
First, to some extent, your code is more a demonstration of the weakness of imperative vs declarative code, since, for example, Haskell lets you declare recursi
by kazagistar 10y ago
First, to some extent, your code is more a demonstration of the weakness of imperative vs declarative code, since, for example, Haskell lets you declare recursive structures directly, since it doesn't enforce an order of execution where none is needed.
data Tree = Leaf Tree | Node Tree Tree
a = Leaf c
b = Leaf c
c = Node a b
But more importantly, there is no reason you can't do this with Optionals.
Tree *a = new Leaf();
Tree *b = new Leaf();
Tree *c = new Node(a, b);
a.parent = b.parent = new Some(c);