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

Champion "Pattern Matching" (16.3, Core 3) #45

Open
2 of 5 tasks
gafter opened this issue Feb 9, 2017 · 16 comments
Open
2 of 5 tasks

Champion "Pattern Matching" (16.3, Core 3) #45

gafter opened this issue Feb 9, 2017 · 16 comments
Assignees
Labels
Implemented Needs ECMA Spec This feature has been implemented in C#, but still needs to be merged into the ECMA specification Proposal champion
Milestone

Comments

@gafter
Copy link
Member

gafter commented Feb 9, 2017

  • Proposal added: proposals/patterns.md
  • Discussed in LDM
  • Decision in LDM
  • Finalized (done, rejected, inactive)
  • Spec'ed

Update: We take this to represent recursive patterns and match expressions. Active patterns should be tracked separately, as they won't happen at the same time.

LDM notes:

@gafter gafter self-assigned this Feb 9, 2017
@gafter gafter modified the milestones: 7.1 candidate, 7.X candidate Feb 21, 2017
@DavidArno
Copy link

Sad to see this slip, yet again, from 7.1 to post 7.2. Please can we have it soon.

@gordanr
Copy link

gordanr commented Mar 10, 2017

@alrz You have very nice, simple and powerful proposal in Roslyn repository.
Proposal: Negative Pattern #16766.
Maybe you could reopen that theme here.

@alrz
Copy link
Contributor

alrz commented Mar 10, 2017

@gordanr Filed issue: #246.

@alrz
Copy link
Contributor

alrz commented Apr 20, 2017

didn't see that coming. http://cr.openjdk.java.net/~briangoetz/amber/pattern-match.html

@DavidArno
Copy link

DavidArno commented Apr 20, 2017

Since I can see the implementation of the other 80% of pattern matching in C# slipping out to beyond v8 (due to the team being so focused on "improving" interfaces at the moment), it wouldn't surprise me if Java gets this stuff before C# does. 😞

@HaloFour
Copy link
Contributor

@alrz

I did. Java 8 made it a warning to use _ as an identifier. In Java 9 it's illegal. I totally expected that to open the path to wildcards in patterns.

@DavidArno

The C# team could push proper pattern matching out to C# 11 and they'd still likely beat Java to the punch. But I expect that the C# team can actually work through interfaces and patterns at the same time, especially since a lot of the groundwork for the latter has been laid and a lot of the work of the former relies on an external team.

It'll be interesting to see where Java goes with the open questions, particularly since they recognize the same scoping issues that the C# team had to work through.

@alrz
Copy link
Contributor

alrz commented Apr 20, 2017

Java 8 made it a warning to use _ as an identifier.

Thank god they do not do fallback-binding thingy. I wonder why C# is reluctant to take such changes. var should've been a keyword by now. I'd prefer warning-waves cripple my build rather than being another compiler flag. That's another example of how C# deals with these changes in a non-breaking way and it does no good for the remaining +80% of users who do not suck.

@DavidArno
Copy link

DavidArno commented Apr 20, 2017

@HaloFour,

I have now stuck a postit note to my monitor that says, in big bold letters, "STOP MOANING ABOUT INTERFACES; YOU ARE BORING EVERYONE". Let's see if I can follow its advice...

@orthoxerox
Copy link

@alrz The other 20% users probably account for 80% of MSFT's DevDiv revenue.

@alrz
Copy link
Contributor

alrz commented Apr 20, 2017

@orthoxerox C++ also did this for auto. C# does not have a bigger audience than those languages.

@HaloFour
Copy link
Contributor

HaloFour commented Apr 20, 2017

@alrz

It's not the first time that Java has broken compatibility. When Java adds a keyword it's not done contextually. It's pretty rare when it happens. I think the last time was Java 5 and assert.

Java 9 will be an interesting experiment. They've been pretty open that this release will potentially break a lot of code, for two major reasons. First, modules, which finally bring a degree of non-visibility to public/protected members, even through reflection. Second, they're finally going to finally remove a bunch of APIs that have been marked deprecated for a very long time. The removal of _ as a valid identifier is peanuts in comparison.

If the pain proves to be too much I could see Oracle pulling their punches going forward, perhaps even regressing a bit in a point release.

@MadsTorgersen MadsTorgersen modified the milestones: 7.X candidate, 7.3 candidate, 8.0 candidate Oct 25, 2017
@gafter
Copy link
Member Author

gafter commented May 9, 2018

A prototype of the latest pattern-matching stuff is available at https://github.com/dotnet/csharplang/wiki/vNext-Preview

@philn5d
Copy link

philn5d commented Nov 14, 2018

I looked for quite some time where to comment and landed here.

Related to this:

https://github.com/dotnet/csharplang/blob/master/proposals/patterns.md

Which I believe is related to "Recursive Pattern" in this msdn blog post about C#8:

https://blogs.msdn.microsoft.com/dotnet/2018/11/12/building-c-8-0/

Which shows the following example:

IEnumerable<string> GetEnrollees()
{
    foreach (var p in People)
    {
        if (p is Student { Graduated: false, Name: string name }) yield return name;
    }
}

Wouldn't it be much more concise to allow:

IEnumerable<string> GetEnrollees()
{
    foreach (Student { Graduated: false, Name: string name } in People)
    { 
        yield return name;
    }
}

and even:

IEnumerable<string> GetEnrollees()
{
    foreach (Student { Graduated: false } as student in People)
    { 
        yield return student;
    }
}

In both cases, only People of type Student with property Graduated == false should be selected. In the first example, Name should also not be null.

In the first example, Name should be assigned to a string variable name.
In the second example, the current Student instance should be assigned to the variable student. The "as" keyword indicates the assignment.

It should be possible to combine as follows:

IEnumerable<string> GetEnrollees()
{
    foreach (Student { Graduated: false, Name string name, StartDate DateTime startDate } as student in People)
    { 
        if(CheckName(name) && startDate < today) yield return student;
    }
}

@HaloFour
Copy link
Contributor

@philn5d

As you're suggesting new syntax I would suggest opening a new issue.

@jcouv jcouv changed the title Champion "Pattern Matching" Champion "Pattern Matching" (16.3, Core 3) Jul 18, 2019
@munael
Copy link

munael commented Sep 10, 2019

@HaloFour , https://github.com/dotnet/csharplang/blob/master/proposals/patterns.md is a 404.

As it stands, it's not really clear what syntax this issue is tracking.

There's a trail of public and LDM discussion history but they mention different parts of things related to pattern matching. It's just not clear what the current idea is.

@alrz
Copy link
Contributor

alrz commented Sep 10, 2019

It's moved to https://github.com/dotnet/csharplang/tree/master/proposals/csharp-8.0 as the feature is marked for the release.

@333fred 333fred added the Implemented Needs ECMA Spec This feature has been implemented in C#, but still needs to be merged into the ECMA specification label Oct 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Implemented Needs ECMA Spec This feature has been implemented in C#, but still needs to be merged into the ECMA specification Proposal champion
Projects
None yet
Development

No branches or pull requests

10 participants