-
Notifications
You must be signed in to change notification settings - Fork 115
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
Contracts and Type Annotations #912
Comments
A better syntax proposal that doesn't use keywords:
So here is a definition for a procedure that mixes all of them:
This could also be attached to an interface:
And method can simply make type assertions because the interface facade has already checked the contracts:
|
We can also extend struct and class definitions to add type annotations to members:
|
|
Don't we need a regular prefix syntax, too? Or are we becoming Rhombus? Better read the Rhombus paper, then... is it out? |
Yes, the prefix syntax will be raw annotation: The |
ok, fair enough, we can us |
although... |
|
Return type annotation can also use
|
Note that this opens the door for the inevitable dependent types further down the road. |
Following discussion with fare, we have reached consensus, although we are not sure about the exact assertion operator name. The current proposal:
|
Other possible symbols for type assertions (@fare wants to uglify them, I want to keep them tidy):
|
Preliminaries in #934; here is the syntactic tokens we settled on:
|
Baby steps towards contracts and type annotations, with the first benefits: `obj.method` syntax for calling interface methods. See #912 for the full picture, which is slated for Benko. Summary of changes: - [x] introduces `using` which handles contract and type annotations for identifiers, and (most importatly) _dotted notation_ for interface method calls and struct/class field/slot access/mutation. - [x] introduces contract violation errors and removes BadArgument; unnecessary at this point. - [x] adds contracts to interface definitions. - [x] introduces dotted notation for interface method calls in the context of `with-type` - [x] refactors the stdlib to use the new goodness. TBD: - [x] documentation - [x] run the postgres test to make sure nothing broke from the refactoring. - [x] add some more interface tests.
this is mostly done with types gerbil, awaiting the v0.18.2 release. |
Following some prototype work some years ago in #417, I have reached some conclusions about the functionality that we want.
def/lambda
forms (they don't have to be in the core prelude, it can be a redef from:std/contract
or:std/typed
).(arg :: predicate-expr)
and they imply a contract generated check and an assertion propagated once the check passes.(arg -: predicate-expr)
and will have the form of programmer declarations. The assertions will be propagated as gospell (trust the programmer, hopefully he is not holding his footgun).>: predicate-expr
and provide information for the compiler to propagate return values. Note that it is not reasonable to generate checks for those, as it will break tail recursion. The compiler can however check (or infer) the return value and emit a warning (or error) if the programmer has made a mistake.:gerbil/typed
language prelude that integrates all of the above.The text was updated successfully, but these errors were encountered: