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.
[Proof of concept] Polymorphic function types #4672
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
[Proof of concept] Polymorphic function types #4672
Changes from 15 commits
951eaf4
0742175
e02b772
6df0adf
91134f7
bb8e5b5
956794e
860c96b
3c6c5a7
390071e
6db3ba4
f809ec4
251a7c4
4761564
6f8ed88
93d3c2a
6c9a5d3
112aa55
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
This should follow the principle used elsewhere: The TypeRef is computed in the lazy val and the context-dependent symbol follows. This is to make sure that the system keeps functioning if Definition classes are edited and recompiled. If you deviate from this, you create confusion for others.
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.
Looking nearby, the pattern seems to be the same as here: the symbol is defined as a lazy val and the typeref as a def. Can you point me to an example which is arranged the way you want it?
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.
E.g.
But I meant to go over
Definitions
anyway, trying to avoid the duplication and make it safe by design. The problem with the lazy val pattern as you wrote it is that it would not work in interactive mode ifPolyFunction
was edited. Thenthe system would hang on to the first version computed instead of the edited ones. I agree that's a rather esoteric use case. So we can leave it for now.
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.
I wonder if we should allow writing such a class
Foo
, rather than just allowing closures — we don't for implicit function types and nobody seems to mind the restriction, and this restriction enables transformations such asShortcutImplicits
. https://github.com/lampepfl/dotty/pull/1775/files#diff-71350811180f41d868e7fb3258fd774dR18There 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.
Note that it can be really useful being able to extend/implement a polymorphic function type; it's one of the use cases I mention in https://github.com/lampepfl/dotty/issues/4670#issuecomment-397819801 – making polymorphic
typecase classes extend the corresponding polymorphic function type.EDIT – typo: "type class" -> "case class"
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.
Ah right, tho
s/type classes/case classes/
. But if we follow the approach for implicit function types,val b: Int => B[Int] = B
could still work by eta-expansion. In fact, it's not clear why eta-expansion doesn't handle that case today by turningB
intoB _
orB.apply
(and I'm not going to try which ones do work, I'd just ask they all work unless backward compatibility gets in the way).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.
@Blaisorblade AFAIK eta expansion never inserts
.apply
calls on things that are not functions. It's true that adding this behavior could be an alternative solution to the stated polymorphic case class problem.