Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
Patterns for self identifiers #752
Patterns for self identifiers
I propose we allow patterns for self identifiers.
The existing way of approaching this problem in F# is an explicit let binding.
type NumberWrapper = NumberWrapper of int with member this.Map f = let (NumberWrapper n) = this f n
With pattern matching for self identifiers, we can write
type NumberWrapper = NumberWrapper of int with member (NumberWrapper n).Map f = f n
Pros and Cons
The advantages of making this adjustment to F# are
The disadvantage of making this adjustment to F# is allowing for too much conciseness?
type NumberWrapper = NumberWrapper of int with member (NumberWrapper (SomeActivePattern (item, KeyValue (Lazy key, value)))).Map f = f (item, key, value)
But isn't this already allowed for parameters? This is just matching them.
Estimated cost (XS, S, M, L, XL, XXL): S
Related suggestions: (put links to related suggestions here)
Affidavit (please submit!)
Please tick this by placing a cross in the box:
Please tick all that apply:
So it comes down to: should records allow
This feature overlaps with #333 .
This has some limited utility I think. The primary use case isn't too bad:
And for multi-case DUs I think most people would prefer a pattern match on
I see this more as a technical limitation than a feature request.
I mean, while learning F# you might think this is already supported and probably all of us realized it is not by trying it.
The spec doesn't specify clearly this doesn't work and by reading about patterns and bindings the user tends to think this should work already. So one could see this limitation as a bug.