-
Notifications
You must be signed in to change notification settings - Fork 39
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
Support user-defined polymorphic type constructors #1073
Comments
The "generality" checking we do on annotations makes it impossible even to use the existing support for type variables in aliases. Given
We get
So polymorphic sum types are out of reach unless we address this issue or change the checking on this rule. |
After a bit of discovery work, here's the high level plan: IR RepresentationWe'll follow the standard approach for representing polymorphic types. Type abstraction represents the type-level variable binding formalized in Type function application will just look operator application, but at the type SyntaxOur current builtin support for polymorphic types looks like this: type-declaration :=
...
| 'type' ID ('[' typeVar? (, typeVar)* ']') = type E.g., to define the type constructor for the option type, we would write type Option[a] =
| Some(a)
| None The existing syntax for type application gives us a form like StaticsTo make the minimal change in our existing type system, we can reuse the Integration with ApalacheI do not currently foresee needing to make any changes for Apalache |
🎉 |
While we support user-defined type aliases, such as
and we allow type variables to appear on the right hand side
we don't support any way for users to define type constructors that are parametric over a type. E.g.,
While we can define
we have no way to express the shared type constraint that would let us define a well typed projection out of that pair:
This would already be useful to allow us to define interfaces over data structures, e.g.:
This will be even more desirable once we have support for sum types. With the addition of user defined polymorphic type constructors, we can define the standard
Option[a]
andEither[a, b]
type constructors (with associated operators). Otherwise, these will have to be implemented as builtins.Discussed with @bugarela who noted
Related to #1062.
As per #1073 (comment), the implementation plan is
The text was updated successfully, but these errors were encountered: