-
Notifications
You must be signed in to change notification settings - Fork 13
[WIP] Infer instantiations for polymorphic arguments to polymorphic functions [rebase of Alex Knauth's PR on bitbucket] #29
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
Open
SuzanneSoy
wants to merge
5
commits into
stchang:master
Choose a base branch
from
SuzanneSoy:infer-poly-4-rebase
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
dbafd4e
lift nested foralls from function result types
AlexKnauth 2261861
infer instantiations for polymorphic arguments to polymorphic functions
AlexKnauth 6247b62
Adjusted some tests for https://bitbucket.org/stchang/macrotypes/pull…
SuzanneSoy 9d812c0
Hopefully not unsound fix for the (Cons (λ ([x : Y]) x) Nil) bug.
SuzanneSoy dea93ab
Fixed another test
SuzanneSoy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would the original test still pass?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, that's one of the remaining issues.
With @AlexKnauth's change which lifts nested ∀ from the function's return type, the outer lambda has type
(∀ (X Y) (→ X (→ Y Y))), but then the value restriction kicks in, and prevents Y from appearing in covariant positions (in case the body was a let-over-lambda capturing the Y type).If I revert that commit, then the outer lambda's type is
(∀ (X) (→ X (∀ (Y) (→ Y Y))))(which sounds good to me as I used Typed Racket a lot, but @AlexKnauth I'm not sure if it is okay to revert that commit). The problem then becomes that(∀ (Y) (→ Y Y))cannot be annotated as(→ Int Int), because the former is not a subtype of the former (an explicit instantiation is needed instead).So I'm trying to see if I can find some combination of changes to
solve+add-constraints+ subtyping which makes everything work.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, yes I'm playing around a bit more and see the behavior you mention. I'm starting to remember now and I think that was one of the original holdups because it means programs like
(((λ ([x : X]) (λ ([y : Y]) y)) 1) 1)will be rejected which is not ideal.Thanks for the update and thanks for work on this!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type of the outer lambda should be
(∀ (X Y) (→ X (→ Y Y)))so that type inference can instantiate eitherXorYif it needs to. Here it needs to instantiateXasInt, butYisn't constrained. So why isYalso solved toInthere?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AlexKnauth I'm not sure what you mean by "why is Y also solved to Int here?", could you clarify? Thanks!
Tentative answer: In that test, the
(check-type … : (→ Int Int))places an expected-type on the outer lambda's return value, which allows theYto be instantiated toInt(but then the return type cannot be left as(→ Y Y), as the value restriction forces it to be monomorphic, IIUC).Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, right. So the test could just as easily be
(check-type … : (→ String String))and it would still pass. TheYin the answer we want should a non-generalizable type variable, like the ones notated'_ain the "Relaxing the Value Restriction" paper.