-
Notifications
You must be signed in to change notification settings - Fork 1.1k
confusing doc page on option-less pattern matching - strange implicit in unapply example #16131
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
Comments
I'd suggest "the most general form is", and note that the type param and the second parameter section are optional. Also, "The different kinds of extractors are characterized by the result type |
Aha, so the implicit param is there just to show that it can be there - but what is it good for? And what is the type B? And where is the type T? (I guess it should be A?) And I still think it should be a given if it must be there? And why x two times - that seems like a compile error ("x is already defined as parameter x") I think it would be better to start off with: def unapply[A](x: A): U
def unapplySeq[A](x: A): U As the above is the normal thing and later then say that a using-part is also possible if needed (but needed for what? And what is B? And we need another name than x for that second mystic using. def unapply[A](x: A)(using y: B): U
def unapplySeq[A](x: A)(using y: B): U
Thanks! This explanation helps a lot to grok why U is there and now the following text makes much more sense. But maybe C instead of U to follow the A B C pattern of type names. |
Oh, good catch! https://discord.com/channels/632150470000902164/632628644035952680/1025685953966256148 on the param name! They used Otherwise, I always prefer simple The reason to show the general signature is that you wonder "will it detect my syntax"? For example, with case classes, it won't generate an apply in the companion if you defined one. Does that include my Any implicit clause or type param would be for benefit of the implementation on the RHS, which the text could make plain. |
Thanks @som-snytt -- happy if you want to coach me here in this PR, to further improve my attempt to fix this: #16132 |
Hello,
I did pretty much exactly that: |
Aha @Sporarum - sorry for not finding that one. Your correction kept the unkonwn T though (not easy to spot for a human who interprets everything as what it should be :) ). How do you want to proceed - there will be a merge conflict of both our PR:s are merged... Perhaps you could split your PR into several ones, one er file or something and then we could manually merge our contributions on patmat? |
Thx, I'll be sure to fix the unknown T ^^ |
I had forgotten to close this issue when #15993 was merged, I will therefore do it now Rest assured your feedback has been taken into account, if you think something is still confusing or incorrect, either reopen this issue or open a new one ^^ |
Uh oh!
There was an error while loading. Please reload this page.
Problem
In this document page:
https://github.com/lampepfl/dotty/blob/main/docs/_docs/reference/changed-features/pattern-matching.md
The initial definition of what an extractor is says that it is a an object having a special unapply looking like this:
Why is there an
(implicit x: B)
? And what is U?The doc page never explains it and I can't find any place in the examples further down where the mystic implicit of type B is used. And if it must be there, should this not be a
using
as this is Scala 3?Proposal
If the implicit is there just to illustrate that there can be an implicit then I think it is better to remove it and just state in the text that a using-parameter is allowed.
The text was updated successfully, but these errors were encountered: