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

Wildcard self identifiers #333

Closed
baronfel opened this issue Oct 20, 2016 · 7 comments
Closed

Wildcard self identifiers #333

baronfel opened this issue Oct 20, 2016 · 7 comments

Comments

@baronfel
Copy link
Contributor

baronfel commented Oct 20, 2016

Submitted by Daniel Robinson on 9/29/2014 12:00:00 AM
9 votes on UserVoice prior to migration

Two underscores are frequently used in member definitions to denote an ignored "self" identifier. This seems like a hack given that the language already provides a wildcard pattern that represents an unused value.

Original UserVoice Submission
Archived Uservoice Comments

@dsyme
Copy link
Collaborator

dsyme commented Oct 29, 2016

I’m marking this as approved in principle for F# 4.×. you are invited to submit a quality and tested implementation would be needed, to be submitted to http://github.com/Microsoft/visualfsharp.
See http://fsharp.github.io/2014/06/18/fsharp-contributions.html for details about contributing to the F# language and core library

FWIW I’ve actually taken a look at this once or twice and it was surprisingly invasive to implement. But by all means give it a go and ask if you need help.

Don Syme BDFL F# Language/Core Library Evolution

@dsyme dsyme mentioned this issue Nov 28, 2017
5 tasks
@eugbaranov
Copy link

@dsyme does this require an RFC?
Any pointers to where is it the best to start?

@dsyme
Copy link
Collaborator

dsyme commented Nov 29, 2017

@Regent In theory an RFC is required but it can be ultra short unless you discover corner-cases in the implementation

For implementation - starting with this:

type C() = 
   member _.P = 1

and compiling using fsc.exe a.fs we get a syntax error. Syntactically _.P is a pattern. Looking through the parsing rules in pars.fsy for memberCore I eventually get down to atomicPatternLongIdent as the thing being parsed

So, the first thing to start is to add _ to the parser in the appropriate place for long identifiers in patterns, e.g.

atomicPatternLongIdent:
  | UNDERSCORE DOT pathOp  { let (LongIdentWithDots(lid,dotms)) = $3 in (None,LongIdentWithDots(ident("_",rhs parseState 1)::lid, rhs parseState 2::dotms)) }

or something like that. One possible problem is that this use of UNDERSCORE might cause conflicts with this:

atomicPattern:
   ...
  | UNDERSCORE 

If so that would be trickier to resolve

@gusty
Copy link

gusty commented May 23, 2019

I tried adding the rule @dsyme suggested at the top level position of atomicPatternLongIdent and it seems to be working fine. See dotnet/fsharp#6829

CC @cartermp

@pblasucci
Copy link

@gusty This is syntax I’ve wanted since 2007 🤪

@gusty
Copy link

gusty commented May 23, 2019

Yes, me too, long time.

It's all green already, either it was easier than what we thought, or a failing test is missing.

@cartermp
Copy link
Member

cartermp commented Aug 2, 2019

Closing as this is in for F# 4.7

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

No branches or pull requests

6 participants