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
Fix toMap
type inference (and some merge
tweaks)
#671
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Currently, there is only one type inference rule for `toMap e : T`, and it requires that `e` is of type `{}`. This adds a second rule which allows a `toMap` expression on a nonempty record type to be annotated with a compatible type. There is prior art for this in `merge t u : T`.
Currently, if you want to annotate a `merge t u` expression, you have to annotate it with a type that exactly matches the type generated by the type inference algorithm. This relaxes that requirement so that it only has to be judgmentally equal to the inferred type. I also removed the `Γ ⊢ t :⇥ { ts… }` precondition; the other precondition, `Γ ⊢ merge t u : T`, implies that `Γ ⊢ t :⇥ { ts… }` so we do not need to state this explicitly. I think it makes the rule clearer: it's more obvious that "a merge expression can always be annotated in a compatible way".
philandstuff
force-pushed
the
allow-tomap-annotation-nonempty-record
branch
from
July 28, 2019 12:07
cc77d7a
to
e187c1a
Compare
Currently, there is no base case for type inference of `toMap e`: the only rule which can infer a type for an expression of the form `toMap e` requires, as precondition, another expression of the form `toMap e` to typecheck. This cyclic dependency effectively means that no expression of the form `toMap e` (without annotation) can typecheck. This commit fixes that, by using `toMap e : T` as the base case instead of `toMap e`. This pattern has prior art in the rules for `merge t u` and `merge t u : T` expressions.
philandstuff
changed the title
Allow
Fix Jul 28, 2019
toMap e : T
where e
is nonempty (and some merge
tweaks)toMap
type inference (and some merge
tweaks)
Gabriella439
approved these changes
Jul 28, 2019
singpolyma
approved these changes
Jul 29, 2019
f-f
approved these changes
Jul 29, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, there is only one type inference rule for
toMap e : T
, andit requires that
e
is of type{}
. This adds a second rule whichallows a
toMap
expression on a nonempty record type to be annotatedwith a compatible type.
There is prior art for this in
merge t u : T
.When I looked at said
merge t u : T
prior art, I noticed that the requirementscould be relaxed.
Currently, if you want to annotate a
merge t u
expression, you have toannotate it with a type that exactly matches the type generated by the
type inference algorithm. This relaxes that requirement so that it only
has to be judgmentally equal to the inferred type.
I also removed the
Γ ⊢ t :⇥ { ts… }
precondition; the otherprecondition,
Γ ⊢ merge t u : T
, implies thatΓ ⊢ t :⇥ { ts… }
so wedo not need to state this explicitly. I think it makes the rule
clearer: it's more obvious that "a merge expression can always be
annotated in a compatible way".
After opening this PR, I noticed that unannotated
toMap e
also cannot typecheck.Currently, there is no base case for type inference of
toMap e
: theonly rule which can infer a type for an expression of the form
toMap e
requires, as precondition, another expression of the form
toMap e
totypecheck. This cyclic dependency effectively means that no expression
of the form
toMap e
(without annotation) can typecheck.I added a commit which fixes that, by using
toMap e : T
as the base case insteadof
toMap e
. This pattern has prior art in the rules formerge t u
and
merge t u : T
expressions.