I am trying to write type for a recursive tree as a record. So the type would look something like this -
type tt = {
type_: string,
value: int,
children: list(tt)
};
But when I do this, it complains type mismatch
let jsont: tt = {
"type_": "node",
"value": 9,
"children": [{
"type_": "node",
"value": 5,
"children": [{
"type_": "leaf",
"value": 3
}, {
"type_": "leaf",
"value": 2
}]
}]
};
The type error reads
This has type:
{. "children": list({. "children": list({. "type_": string, "value": int}),
"type_": string, "value": int}),
"type_": string, "value": int}
But somewhere wanted:
tt
How do I write children to be optional?