New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed contracts #374
Closed contracts #374
Conversation
9e63ba0
to
b617d10
Compare
7c2fe49
to
7199f18
Compare
35df3b7
to
00d3141
Compare
🎉 All dependencies have been resolved ! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like this.
Just a very minor comment that you can feel free to ignore, but otherwise 👍
impl Default for RecordAttrs { | ||
fn default() -> Self { | ||
RecordAttrs { open: false } | ||
} | ||
} | ||
|
||
impl RecordAttrs { | ||
pub fn merge(attrs1: RecordAttrs, attrs2: RecordAttrs) -> RecordAttrs { | ||
RecordAttrs { | ||
open: attrs1.open || attrs2.open, | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(nit) This looks a lot like a monoid. Isn’t there a standard trait for that in Rust?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point (and typical Haskeller 😛 ), but I can't find one in the standard library, just in some third-party crates, so I guess I'll leave it as it is.
Closed contracts Implement contract mode for merging
Depend on #370. Fix #303.
Summary
This PR implements the fix proposed in #303: it makes the contract application operator
let Contract = { a | Num } in value | #Contract
more restrictive than justvalue & Contract
, in that it now raises a contract violation ifvalue
has an extra field other thana
.Contract application having a different behavior than merge for record contracts is nice, because beside contract application now doing the correct thing (by default a schema shouldn't allow extra fields), one can still use standard merging on closed contracts to compose them:
Open contracts
This PR introduces a new ellipsis syntax
..
to stipulate thatContract
allows extra field, as in the workinglet Contract = {a | Num, ..} in {a = 1, b = 2} | #Contract
. With the ellipsis, a record contract behaves as before this PR.The behavior with respect to merging is that if any of the operands is open, then the resulting contract is open. The rationale is that
..
can be imagined as a special field that is syntactically merged as any other field:{a | Num} & {..} = {a | Num, ..}
.