Replies: 3 comments 20 replies
-
@333fred, wondering if the LDM notes are more for "later referal in future meeting on same topic" or for engaging with people outside the meeting participants, that would like to contribute feedback? I personally enjoy the notes being published, but seem to have difficulty to connect with the context that maybe obvious when you are in the meeting, because for exemple, in this case, there is no reference material, to at least scope better at first glance, what it is about, until I've finished a cursory reading. Suggestions for this:
Small feedback of what I gleaned:
It would be great to see pseudo code of what would be confusing to code readers in the context of that statement.
This sounds great, conceptually, pattern should remain composable, the patterns may be little "involved" but they do encode things most concisely and statically compared to the structures they end up desugaring to (nested if/else/switch, etc.), so reasoning about code, after being acquainted to the pattern syntax eventually become easier than the expanded form.
Wondering if as an alternative of baking custom pattern syntax in the language as hardcoded implementation details, you would be considering options where the C# compiler has definitions like "macros" that monomorphizes at the instanciation site. A bit like, what I believe, some of the pattern NonEmpty(list_like list){
if(has_prop(int Length, list)) {
// implementation of pattern if Length exists
}
else if(has_prop(int Count, list)) {
} else {
// substitution failure is a compile error, saying nice things about list like and what the code tried to pattern match over
}
} using it: x switch {
NonEmpty => ...
} If there is a concern about mixing with normal identifiers, the pattern may be adorned with a special character, or couple of them, indicating the nature of the construct. Taking this approach to extend patterns would:
The patterns could even look a bit like keywords instead of dotnet BCL identifiers. If C# extends internally this way, and does so successfully in terms of tooling support and end user experience, the infrastructure would later possibly be for C# code authors to leverage, enabling scenarios similar to F# active pattern (which are much simpler concept as they just desugar to methods returning I personally don't enjoy patterns leaning heavily on operator syntax unless the operators tend to carry outside the pattern matching situations, AFAIK, there is no Have you considered those: x switch {
[]{a, b} => // match 2 element array
List<int>{a,b} => // match 2 element List<int>
NonEmpty => // anything list like, which is non empty
_ => // anything else
} Sorry for digression, and looking forward for future LDM notes :) |
Beta Was this translation helpful? Give feedback.
-
A small discussion in Twitter shows that almost no one can guess what |
Beta Was this translation helpful? Give feedback.
-
It could be then |
Beta Was this translation helpful? Give feedback.
-
https://github.com/dotnet/csharplang/blob/main/meetings/2021/LDM-2021-05-26.md
Agenda
Beta Was this translation helpful? Give feedback.
All reactions