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.
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
SIP-56 - Proper Specification for Match Types. #65
SIP-56 - Proper Specification for Match Types. #65
Changes from 1 commit
4ae0ee0
cb6b892
afbd365
17fe545
cc9c90a
3c6b360
580d30b
7e9e856
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.
💪 👏
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.
👏
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.
@dwijnand you might have something to say about this? I know it's come up repeatedly in our discussions about match types that it's possible to use them to smuggle in something akin to abstract type projections.
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.
With the proposed spec, only concrete type projections actually make it. As long as it's abstract,
ExtractTOf[A]
cannot reduce toT
likeA#T
does. The difference is thatA#T
has the "best" bounds ofT
inA
, whereasExtractTOf[A]
has only the match type's bound as long asT
is not concrete (through subsequent substitution ofA
by something more precise in whichT
is a type alias whose rhs does not depend on its prefix).For example,
The match-type-based type member extractor still features enough power because you can "carry around" values of that type, and at the edge your
B
becomes concrete enough that you can reduce. This is what happens withscala.Enumeration
s.IMO, people should not use that. It's all a hack. Instead, we should use path-dependent types with actual values of the enclosing class. For example the proper definition of
fooOfBase
is:Unfortunately, people have been using type projections/type member extractors instead. Yes, sometimes it avoids one extra layer of nesting: if you need a class that
extends Foo[b.type]
, you wouldb
to be declared one level up, and so that class needs to be nested in another class that has ab
field. This is why the json4s workaround is what it is, instead of turning it into path-dependent types. The correct solution would be to havebut that would have changed the public API, so it was not an acceptable PR to make.
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.
So if I understand correctly, the currently unspecified Match-types brings some expressive power from Scala 2's type projections T#A with respect to type member extraction as in the use case of computing the type of a member in an enum. This seems useful. Currently the proposal seems to state that this expressive power should be removed with no workaround. I think that the proposal needs a discussion on what can be done about this or why this particular case is not included among the legal cases as a special case or something similar. Or is it unsound to ask for the type of enum members? (sorry if this is a nonsensical question)
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.
Hum no, the sentence says: if we remove type member extractors from the proposed spec, then we will have no workaround anymore. With the proposed spec, we can extract type members.
The originally submitted SIP/spec did not allow to extract the type member of
SomeEnumeration#Value
becauseValue
is a class member (not a type alias), but the commit "Allow class members to be matched by type member extractors." made that actually possible.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 thanks for the clarification!