-
Notifications
You must be signed in to change notification settings - Fork 81
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
[Dogfooding] Nullable of several contracts (or, union of intersections) #461
Comments
I’m a bit skeptical of the |
I guess it's a matter of taste. To me it quite reflects the actual semantics of the "intersection", as it says apply contracts
which is almost what the former several contracts application desugar to, modulo labels and conversion of contracts-as-record to contracts-as-function. However, the problem is that this construction is not first class, either on the value side (we can't write Once again, there are two "worlds", or syntactic categories, to consider: the values side, and the types side. Introducing an On the values sides, it would make sense to use merging indeed, such as It would be more limiting though, as we can't merge a builtin type. Another solution would be to have something dual to |
I’m wondering whether having a “merging” for functions similar to the one for records would make sense (disclaimer: At least at a first look it’s unbearably complex). If we consider records as a special-case of functions (that map each label to its value), then we can have a “natural” extension of
where (except that we’d need to extend that to merging arbitrary intersections, and that gets a bit hairy) Where this is interesting compared to an unrestricted set-theoretic intersection is that (I hope) the intersections only happen between arrows with a distinct codomain, meaning that there’s an immediate witness of which branch should be taken (like for discriminated unions). At least on the paper it looks like it could lead to a somewhat decent semantics (as long as we don’t pretend that it’s an intersection), and solve the issue as it would just become a Nullable of the merge of several contracts. But it’s Friday afternoon, so maybe this is just all nonsense. |
Closing as this is solved by |
Is your feature request related to a problem? Please describe.
During dogfooding on the mantis repo, I had to convert CUE types that are morally unions of intersections, as this one. In this example,
Weight
is either:null
Intersections alone (on simple contracts like this, at least: see the paper reference at the end for more info) can just be represented as several contract applications in Nickel. If we take
Weight
to be NON nullable, we can simply translate this as:A nullabe alone is also not so bad. If we forget the bound
-100
and100
, then we could write it like:Or even
Weight | #Nullable #nums.Nat
(under the proposal #445).The problem is that when we mix everything, we cannot pass a series of contract application
| #nums.Nat | ...
toNullable
: that is, intersection of contracts is not first class. Currently we need to do something like:While not awful, it is quite more verbose and different than without the
Nullable
: in one case we just use standard contract application in sequence, but in the other we need a new combinatorAllOf
.Describe the solution you'd like
I don't really know of a great solution. We can't have general union and intersection contracts for deep reasons: we actually published a paper about this very specific subject this year. So adding a syntax to do that, even in limited cases, could be very misleading and error prone in case of misuse. I just wanted to report this quirk to see if someone has a better solution on how to handle this.
The text was updated successfully, but these errors were encountered: