The intended semantics of @tag is to only modify the tag for cases with payloads.
It’s not intended to introduce an entirely new representation with tags everywhere.
You can also do it with an optional “dummy” field in an inline record, that you then just never supply:
@tag("type")
type t =
| A({index: int})
| B({__dummy?: unit})
let a = A({index: 1})
let b = B({})
var a = {
type: "A",
index: 1
};
var b = {
type: "B"
};
That omits the _0 payload.
We’ve been discussing allowing empty inline records, which would make expressing what you’re after possible in an idiomatic way without resorting to “hacks”. In that scenario, you’d just define B as B({}) and it’d be represented as you’d expect, with no additional cruft.