Union of contracts #1598
Replies: 1 comment 1 reply
-
It does indeed seem to be impossible to express this with fully lazy contracts, which record contracts in Nickel are supposed to be. Currently, the best workaround would be to write a custom contract that asserts that only one of the fields is present. So maybe something like
could work. But that's not particularly scalable or user friendly and we're actively trying to figure out a reasonable system. See for example #1533 and #1448. Note also, that we're having this exact problem with the JSON Schema to Nickel converter. Actually, that might lead to a slightly more scalable approach: write a JSON schema for this particular subcontract and then use the generated code. In essence that tool generates pretty much the code that I've written here, but it does it automatically. EDIT: Actually check |
Beta Was this translation helpful? Give feedback.
-
Hello - am I right in thinking that it's not currently possible to express the idea in Nickel that a record might have one field, or another - like this?
I've read https://www.tweag.io/blog/2022-04-28-union-intersection-contracts/ but I'd like to double-check my understanding. If this is the case, is there an idiomatic work-around?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions