Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Gets rid of typing rule for record identifiers#4380

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
mikesol wants to merge1 commit intopurescript:master
base:master
Choose a base branch
Loading
frommikesol:get-rid-of-typing-rule-for-record-identifier

Conversation

mikesol
Copy link

Description of the change

Allows records with constrained terms to typecheck.

Checklist:

  • Added a file to CHANGELOG.d for this PR (see CHANGELOG.d/README.md)
  • Added myself to CONTRIBUTORS.md (if this is my first contribution)
  • Linked any existing issues or proposals that this pull request should close
  • Updated or added relevant documentation
  • Added a test for the contribution (if applicable)

@mikesol
Copy link
Author

It looks like there are a couple regressions when removing this check, ie:

moduleMainwhereimportPreludeimportEffect.Console (log)dataXa =Xx::foralla.Xax =XtypeY={x::XInt}test::forallm.Monadm=>mYtest = pure { x: x }typeZt=forallx.tx-> (foralla.ta)->txclassCtwhere c::ZtinstancecA ::CArraywhere  c x _ = xtest2::forallm.Monadm=>m{ccc::ZArray}test2 = pure { ccc: (c::ZArray) }main = log"Done"

yields

 Thetype variable x, bound at                  tests/purs/passing/1110.purs:16:12 - 16:51 (line 16, column 12 - line 16, column 51)                has escaped its scope, appearingin thetype                                                                      { ccc :: Array x6 -> (forall a. ...) -> Array x6           }in the expression { ccc: c cA                         }in value declaration test2

@natefaubion
Copy link
Contributor

natefaubion commentedAug 21, 2022
edited
Loading

That's correct, this check is not benign. I would expect there to be failures because it is no longer inferring polytypes in records. This test specifically tests what the rule is meant to support.

@natefaubion
Copy link
Contributor

natefaubion commentedAug 21, 2022
edited
Loading

test2::forallm.Monadm=>m{ccc::ZArray}test2 = pure { ccc: (c::ZArray) }

I think this is an expected failure, not dissimilar fromrunST $ ..., as the polytype would have to be threaded through the record constructor and the call topure. It may work if you annotate the record as a whole, rather than justc.

@mikesol
Copy link
Author

If the rule currently provides inference for polytypes for records & if the PR causes a regression, maybe this PR isn't a good candidate for merging?

@natefaubion
Copy link
Contributor

We don’t infer polytypes in records other than the special case of bare identifiers. I personally think this special case causes far more trouble than it’s worth.

@mikesol
Copy link
Author

I'm in a bit over my head as it's a part of the compiler I don't know well, but is there any way to avoid the regression while achieving the desired behavior?

@natefaubion
Copy link
Contributor

natefaubion commentedAug 22, 2022
edited
Loading

There is no way to specifically have the compilerinfer:

{ wat: mempty }
{ wat :: forall a. Monoid a => a }

Given our current approach. Generally we do not infer polymorphism. We only let generalize at the top level. This is a special case for records which doesn't otherwise exist in any other construct in the language.

The way to fix this would be to push more information down as part of checking, so it could check this field as being polymorphic. This would require a better treatment of first-class polymorphism like QuickLook or "dynamic order elaboration".

@garyb
Copy link
Member

You've stumbled into something that we've talked about for years here@mikesol, I'm not sure if you're aware of that / would pick it up from what Nate is saying. The fact that it will break some existing things is perhaps partially why nobody has gotten too much into it despite it being an occasional topic for a long time, but it doesn't necessarily mean we shouldn't do it.

I think the first time I remember a discussion about it was Phil saying he thought we should restrict record properties to monotypes in like 2014 when I met up with him in person. 😄

MonoidMusician reacted with laugh emoji

@JordanMartinez
Copy link
Contributor

Just to clarify, this is a breaking change, right? As some code that currently compiles would likely no longer compile?

@natefaubion
Copy link
Contributor

That's correct, this is necessarily a breaking change.

@purefunctor
Copy link
Member

An adjacent change to this is#4376. Constructors were made to infer into monotypes to align with the typing rule here. In my changeset, I just hoisted up this predicate and added a special case for singleton constructors.

garyb reacted with eyes emoji

@mikesol
Copy link
Author

mikesol commentedAug 24, 2022 via email

Yikes, my brief forays into the compiler always land me in hornets nests!!I don't think I'm the right person to get this PR over the finishing line -as it's a breaking change, someone with a bit more knowledge of theecosystem should make the call if this is a good path forward. Or maybe askabout it on the next survey in ~6 mo?
On Mon, 22 Aug 2022, 23.35 Gary Burgess, ***@***.***> wrote: You've stumbled into something that we've talked about for years here@mikesol <https://github.com/mikesol>, I'm not sure if you're aware of that / would pick it up from what Nate is saying. The fact that it will break some existing things is perhaps partially why nobody has gotten too much into it despite it being an occasional topic for a long time, but it doesn't necessarily mean we shouldn't do it. I think the first time I remember a discussion about it was Phil saying he thought we should restrict record properties to monotypes in like 2014 when I met up with him in person. 😄 — Reply to this email directly, view it on GitHub <#4380 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAEAIJQWAS6RTWXZ55DDO7TV2PQBZANCNFSM57FKB2JA> . You are receiving this because you were mentioned.Message ID: ***@***.***>

@purefunctor
Copy link
Member

If we follow through with this change, we should also free the special case done for constructors in#835. Constructors inferring to monotypes instead of polytypes is currently a blocker for visible type applications. There's#4376 of course, which effectively just defers the hoisting for constructors.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Projects
None yet
Milestone
v0.16.0
Development

Successfully merging this pull request may close these issues.

5 participants
@mikesol@natefaubion@garyb@JordanMartinez@purefunctor

[8]ページ先頭

©2009-2025 Movatter.jp