Hacker News new | ask | show | jobs
by jez 1047 days ago
Your solution is the second alternative proposed in the article: the “Nullable field” solution.

It’s an example of a classic tradeoff between enforcing correctness and invariants “by construction” vs at runtime. Since the field is nullable, the AST is not necessarily correct by construction, as the programmer may have forgotten to include a type when required. The correctness of compilers using such representations involves either checked or unchecked assertions where the type field is used to ensure that it is set appropriately.

The article continues with various strategies to avoid needing to defer this correctness checking to the runtime by providing various statically-checked alternatives.