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 support for the variant operator in the type and effect system #1209

Merged
merged 13 commits into from
Oct 20, 2023

Conversation

shonfeder
Copy link
Contributor

@shonfeder shonfeder commented Oct 6, 2023

Addresses the first half of #244.

The variant operator is the builtin operator introduced in #1206 that injects a value into a sum type. I.e., type T = A(int) | B; val a : T = variant("A", 42).

This PR adds support in the type system for checking and inferring the type of this operator.

The most significant change is the introduction of a new constraint isDefined(t) which holds when the type schema t unifies with a defined type. This is required and foretold by the RFC001, approved in #1062. It ensures that users cannot introduces open-rowed variants, since we have decided that the complexity of allowing open, anonymous variant types is undesirable.

This PR also corrects the logic around generating the sum type injector operators introduced in #1206.

Please see the commit messages for context. Review by commit my also be helpful.

  • Tests added for any new code
  • Documentation added for any new functionality
  • Entries added to the respective CHANGELOG.md for any new functionality
  • Feature table on README.md updated for any listed functionality

@shonfeder shonfeder marked this pull request as ready for review October 6, 2023 21:37
@shonfeder shonfeder changed the title 244/sum types type system Add support for the variant operator in the type and effect system Oct 6, 2023
Copy link
Collaborator

@bugarela bugarela left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Only very minor comments.

quint/src/types/specialConstraints.ts Outdated Show resolved Hide resolved
quint/test/types/constraintSolver.test.ts Outdated Show resolved Hide resolved
quint/test/types/constraintSolver.test.ts Outdated Show resolved Hide resolved
Shon Feder added 12 commits October 20, 2023 15:42
This also requires adding a new constraint `isDefined` that holds iff a
type that unifies with the given type is defined in the context.
Allows us to find and transform values from an iterable
- Nullary constructors where being incorrectly defined as lambdas, when
they should just be values.
- We were not adding the type annotation of the defined type to the
operator. But we want this, since in ensures we do not construct open
rowed variants and ensures that we have the right topological sorting to
ensure the variant constructors are after the defined types.
@shonfeder
Copy link
Contributor Author

Thanks for the review and for catching my oversights.

@shonfeder shonfeder merged commit 8058121 into main Oct 20, 2023
15 checks passed
@shonfeder shonfeder deleted the 244/sum-types-type-system branch October 20, 2023 20:11
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.

None yet

2 participants