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

Strange interpretation of a free type variable in a method type in a signature #7465

Closed
vicuna opened this issue Jan 23, 2017 · 9 comments
Closed

Comments

@vicuna
Copy link

vicuna commented Jan 23, 2017

Original bug ID: 7465
Reporter: @fpottier
Assigned to: @garrigue
Status: confirmed (set by @garrigue on 2017-01-24T07:54:20Z)
Resolution: open
Priority: normal
Severity: feature
Category: typing
Monitored by: @gasche @yallop

Bug description

See attached file bizarre.ml.

The comparison between the signatures M1 and M3 fails,
whereas I thought it should succeed.
The type error message shows that the type of the method check,
which is declared as "method check: 'c",
is interpreted as "method check: 'c . 'c".
Is this behavior intended?
It seems to me that there should NOT be an implicit universal quantification
over 'c at the level of the method.

This is all the more surprising since the comparison between M1 and M2 succeeds.
(This seems correct.)
This shows that the declaration "method check: 'a . 'c"
is correctly interpreted as "method check: 'c"
where 'c is a free variable.

File attachments

@vicuna
Copy link
Author

vicuna commented Jan 24, 2017

Comment author: @garrigue

This is the expected behavior: in a class type, a free type variable in a method is generalized, as otherwise the class type would be invalid, hence the meaning for M3.
However, if the type variable already appears in a constraint (M1) or if an explicit polymorphic type is given (M2), this is not the case.

This behavior was chosen to simplify the writing of polymorphic methods, particularly when there are row types involved.

But you have a point here: since in M3 the type of self is captured by a type variable, and as a result the type where 'a is not quantified would still be valid,, it would be more natural to have the same behavior as M1 and M2. In theory, this is a change in behavior, but in practice I would not expect this to break anything. We would still need a clear criterion for that.

@vicuna
Copy link
Author

vicuna commented Jan 24, 2017

Comment author: @fpottier

Hi Jacques.
Yes, my thinking is that if the class is parameterized over the type of self, then the equality constraint 'self = < list of all methods; .. > should be implicitly added to the class type. That should allow the method types to contain free type variables, without creating problems.

@github-actions
Copy link

github-actions bot commented May 9, 2020

This issue has been open one year with no activity. Consequently, it is being marked with the "stale" label. What this means is that the issue will be automatically closed in 30 days unless more comments are added or the "stale" label is removed. Comments that provide new information on the issue are especially welcome: is it still reproducible? did it appear in other contexts? how critical is it? etc.

@github-actions github-actions bot added the Stale label May 9, 2020
@garrigue
Copy link
Contributor

garrigue commented May 9, 2020

@fpottier I don't see why it should be so. Currently the criterion is that any type variable in a method type that is not explicitly bound in a class parameter or a contraint is interpreted as universal in the method type. This seems a simple enough criterion. It would be strange that just having the type of self appear in a parameter should change this behaviour, and there is nothing wrong in having polymorphic methods appear in the type of self.

@fpottier
Copy link
Contributor

fpottier commented May 9, 2020

I am not suggesting any change. Actually, the behavior that surprised me at the time is documented in the manual ("The polymorphism may be left implicit in public method specifications: any type variable which is not bound to a class parameter and does not appear elsewhere inside the class specification will be assumed to be universal, and made polymorphic in the resulting method type. Writing an explicit polymorphic type will disable this behaviour."). But, because the manual does not contain any examples, it is actually fairly difficult to understand what it means...

@gasche
Copy link
Member

gasche commented May 9, 2020

So you are suggesting to add examples to the manual. Would you be willing to submit them as a PR?

@fpottier
Copy link
Contributor

I wrote about some of my findings in the visitors manual (Section 4), but I wouldn't have time at the moment to turn that into a PR, sorry.

@github-actions github-actions bot removed the Stale label Jun 10, 2020
@github-actions
Copy link

This issue has been open one year with no activity. Consequently, it is being marked with the "stale" label. What this means is that the issue will be automatically closed in 30 days unless more comments are added or the "stale" label is removed. Comments that provide new information on the issue are especially welcome: is it still reproducible? did it appear in other contexts? how critical is it? etc.

@github-actions
Copy link

github-actions bot commented Jul 1, 2022

This issue has been open one year with no activity. Consequently, it is being marked with the "stale" label. What this means is that the issue will be automatically closed in 30 days unless more comments are added or the "stale" label is removed. Comments that provide new information on the issue are especially welcome: is it still reproducible? did it appear in other contexts? how critical is it? etc.

@github-actions github-actions bot added the Stale label Jul 1, 2022
@github-actions github-actions bot closed this as completed Aug 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants