Skip to content
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

Pattern matching documentation #2565

Merged
merged 2 commits into from
May 31, 2017
Merged

Conversation

OlivierBlanvillain
Copy link
Contributor

@odersky @DarkDimius This is very minimal, anything else you would like to see included?

def apply(i: Int, s: String): CC = new CC(i, s)
def unapply(cc: CC): CC = cc
}
```
Copy link
Contributor

@felixmulder felixmulder May 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A reference to this page needs to be added to sidebar.yml and index.md to be visible to all :)

@smarter
Copy link
Member

smarter commented May 29, 2017

Does this describe the current state of Dotty after 3e04b6f ?


Boolean Pattern

- Extractor defines `def unapply(x: T): Boolean`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be nice to give examples instead of rules. More accessible.


In case of ambiguities, *Product Pattern* is preferred over *Name Based Pattern*.

Dotty pattern matching is not special cased to case classes. Instead, allocation of Tuples and Options is avoided by desugaring case classes to use a *Product Pattern* extractor:
Copy link
Contributor

@DarkDimius DarkDimius May 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear what does this mean without context. I think we should either introduce scalac story here, or simply drop this sentence.

@DarkDimius
Copy link
Contributor

anything else you would like to see included?

I'd propose to include that Dotty-generated patterns are a LOT easier to debug, as variables will show-up in debug modes.

Copy link
Contributor

@DarkDimius DarkDimius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small suggestions, Otherwise LGTM

- Add a bunch of links to dotty.epfl.ch
- Clean up / update the features list
@OlivierBlanvillain
Copy link
Contributor Author

@DarkDimius I've incorporated your suggestions, I think the pattern matching doc needs another review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants