Skip to content
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

Add boolean contract combinators to the stdlib #1995

Merged
merged 4 commits into from
Jul 17, 2024
Merged

Conversation

yannham
Copy link
Member

@yannham yannham commented Jul 15, 2024

Depends on #1987

This commit adds the boolean combinators one_of, not and all_of to the contract module of the stdlib. They are implemented in the obvious way, by making immediate decisions based on the immediate part of their contract operands. The limitations and possible work around are detailed in the documentation and in the manual.

I considered the addition of one_of, to adhere to the JSON schema terminology, but it turns out that it seems pretty useless for the time being, because record contracts are mostly delayed and I couldn't come up with a simple compelling example that would work in the current setting, where one_of would be needed over any_of. The standard example is two record contracts with an non-empty intersection, like {employee_id, name, ..} and {student_id, name, ..}, but this can't work as expected currently as the check for missing fields is delayed. I suspect we need to wait for proper full eager versions of builtin record contracts for a simple example (one can write the previous example with specialized custom contracts, but it starts to be involved - the fact that I can't come up with a short example to put in the documentation of the function leads me to think that it's too early to introduce this function)

@yannham yannham requested a review from jneem July 15, 2024 19:27
@yannham yannham marked this pull request as draft July 15, 2024 19:27
@github-actions github-actions bot temporarily deployed to pull request July 15, 2024 19:29 Inactive
@jneem
Copy link
Member

jneem commented Jul 16, 2024

I think oneOf is pretty useless in general, not just in nickel...

@yannham yannham marked this pull request as ready for review July 16, 2024 10:27
@yannham
Copy link
Member Author

yannham commented Jul 16, 2024

I think oneOf is pretty useless in general, not just in nickel...

Yeah, it's hard to think of a good, natural use-case. I imagine they might exist. Let's implement it lazily: wait for someone to come with a need for it.

Otherwise, it's ready to review now @jneem (sorry about the early ping, I requested your review too soon, before adding tests)

@github-actions github-actions bot temporarily deployed to pull request July 16, 2024 10:30 Inactive
core/stdlib/std.ncl Outdated Show resolved Hide resolved
core/stdlib/std.ncl Outdated Show resolved Hide resolved
core/stdlib/std.ncl Outdated Show resolved Hide resolved
core/stdlib/std.ncl Show resolved Hide resolved
doc/manual/contracts.md Outdated Show resolved Hide resolved
doc/manual/contracts.md Outdated Show resolved Hide resolved
@github-actions github-actions bot temporarily deployed to pull request July 17, 2024 09:05 Inactive
@github-actions github-actions bot temporarily deployed to pull request July 17, 2024 09:25 Inactive
@yannham yannham force-pushed the task/immediate-parts-builtin-contracts branch from 01ca07a to 375dccd Compare July 17, 2024 09:37
Base automatically changed from task/immediate-parts-builtin-contracts to master July 17, 2024 10:03
Copy link

dpulls bot commented Jul 17, 2024

🎉 All dependencies have been resolved !

yannham and others added 4 commits July 17, 2024 12:11
This commit adds the boolean combinators `one_of`, `not` and `all_of` to
the contract module of the stdlib. They are implemented in the obvious
way, by making immediate decisions based on the immediate part of their
contract operands. The limitations and possible work arounds are
detailed in the documentation and in the manual.
Co-authored-by: jneem <joeneeman@gmail.com>
Make a pass on the new documentation of boolean contract combinators to
implement the reviewer's suggestions.
@github-actions github-actions bot temporarily deployed to pull request July 17, 2024 10:15 Inactive
@yannham yannham added this pull request to the merge queue Jul 17, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jul 17, 2024
@yannham yannham added this pull request to the merge queue Jul 17, 2024
Merged via the queue into master with commit 6be1f2c Jul 17, 2024
5 checks passed
@yannham yannham deleted the feat/one-of-final branch July 17, 2024 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants