Alternative encoding of optional values in preserves-schema.md

This commit is contained in:
Tony Garnock-Jones 2021-09-30 14:46:35 +02:00
parent 0507ab2f38
commit 5fded03fa4
1 changed files with 4 additions and 5 deletions

View File

@ -182,16 +182,15 @@ Intersections are an experimental feature. They can be used to express
*optional dictionary entries*:[^not-ideal-optional-encoding]
MyDict = {a: int, b: string} & @c MaybeC .
MaybeC = @present {c: symbol} / @absent {} .
MaybeC = @present {c: symbol} / @invalid {c: any} / @absent {} .
It is not yet clear whether they pull their weight. In particular, the
semantics of serializing a value defined by intersection are not
completely clear.
[^not-ideal-optional-encoding]: This encoding is not ideal. Given a
term `{a: 1, b: "", c: sym}`, it will yield a `present` result,
and given `{a: 1, b: ""}`, will yield an `absent` result; but
`absent` will also result from `{a: 1, b: "", c: "notasymbol"}`.
[^not-ideal-optional-encoding]: This encoding is not ideal. It passes
responsibility for checking for invalid inputs up to the user,
rather than handling it completely at the Schema layer.
### Patterns.