Core: document header structure and use `when<>` in `datatype<>`