-
Notifications
You must be signed in to change notification settings - Fork 92
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
std.contract.from_validator
is hard to use in statically typed code
#2050
Comments
The rationale was that I expected people would use However, I do agree that it's annoying to use in statically typed code. The issue is that Another simpler solution is to have a statically typed variant As an aside, the easiest right now to just disable typechecking on such contract definitions is probably to write |
Note that by fundamental design of Nickel, a contract annotation disables the typechecker for the annotated term. So basically |
Oh I see. For some reason I thought that annotating |
It's not really that it ignores |
Ok, so then I'm confused again that
|
Ah, I didn't understand your question properly then, sorry. It shouldn't work, indeed. Could you provide the full example? One possibility that I see is the recent bug over contract equality that has been fixed in |
It seems to have been the contract equality thing indeed. Updating to latest master raises an error as expected. Sorry about the noise! |
std.contract.from_validator
takes an argument of typeDyn -> [| 'Ok, 'Error { message | String | optional, notes | Array String | optional, } |]
, but it's annoying to produce a literal of that type. For example, considerThis runs ok, but as soon as I wrap it in
(...) : _
it errors withMaybe this is another situation where we can use subtyping?
A work-around is to annotate the record type, like
{message = "blah"} | { message, notes | optional }
but that's a bit verbose. Also, I'm a little surprised that this annotation passes the typechecker despite not supplying a type fornotes
.The text was updated successfully, but these errors were encountered: