confusing doc page on option-less pattern matching - strange implicit in unapply example
See original GitHub issueProblem
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:
def unapply[A](x: T)(implicit x: B): U
def unapplySeq[A](x: T)(implicit x: B): U
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.
Issue Analytics
- State:
- Created a year ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Option-less pattern matching
Extractors that expose the method unapply are called fixed-arity extractors, which work with patterns of fixed arity. Extractors that expose the method ...
Read more >pattern match,"::" unapply confusion - scala
I learned that this code is pattern match and it calls unapply method actually. But when I write code in this way, compiled...
Read more >StreetSmart Edge® User Guide
What is chart pattern recognition? Chart pattern recognition in StreetSmart. Edge® is provided to users by a third party program from Recognia.
Read more >Residence Rules in the Decennial Census
Bureau document, although a somewhat edited version of the rules was posted on the Census Bureau Web site during the 2000 census.1 The...
Read more >Federal Register, Volume 86 Issue 205 (Wednesday ...
[Federal Register Volume 86, Number 205 (Wednesday, October 27, 2021)] [Rules and Regulations] [Pages 59452-59593] From the Federal Register ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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:
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.
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.
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
U
.”