Hacker News new | ask | show | jobs
by ForLoveOfCats 2130 days ago
I think that the parent commenter was referring to overuse of Box and reference counting. However the compiler does know the size as it is an enum (a sum type) which means it is effectively a discriminated union that the compiler forces you to check the type of.
1 comments

If the enum is recursive (which will often be the case, since expressions can be nested in most languages), then you'll still need to use `Box` (or some other indirection) for some of the child nodes.
That's a good detail to note, thanks. I wanted to note that the size of the enum itself is indeed known at compile time otherwise the compiler would complain (such as if it is improperly recursive). The point is mute though as a tree like this would usually be built on the heap anyway (whether that be an arena or normal allocation)