question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

confusing doc page on option-less pattern matching - strange implicit in unapply example

See original GitHub issue

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:

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:open
  • Created a year ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
bjornregnellcommented, Oct 1, 2022

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

“The different kinds of extractors are characterized by the result type 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.

1reaction
som-snyttcommented, Oct 1, 2022

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.”

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found