-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Notes on Records and Pattern Matching for 2015-10-07 design review #5757
Comments
This discussion will be moved to next month's design review because I'm home sick today. |
Please consider these features as well:
Will record types be solely immutable? I think the ability to define EF entity classes or attributes as record types are reasonable enough to make record types not-solely-immutable. Even F# as a functional language has |
@gafter So, there would be a |
To make the record class mutable you define the properties with |
I was thinking about a more concise syntax like |
@alrz Pattern matching is part of a set of features intended to make safer things easier to do. Mutation is not one of the safer things we are trying to make easier. |
Design notest have been archived at https://github.com/dotnet/roslyn/blob/future/docs/designNotes/2015-10-07%20C%23%20Design%20Review%20Notes.md but discussion can continue here. |
Records and Pattern Matching (#206)
Prototyped together last year by @semihokur, but that prototype is
based on very out-of-date Roslyn code. We also have some design changes
since that time and we want to separate a pattern-matching prototype from
records/ADTs so we can make independent decisions about whether
and when to include them in the language(s).
First step is to port pattern matching to the latest sources.
In-progress port at #4882
Spec changes since the 2014 prototype
For pattern matching:
if
)switch
statement that make it a compatible extension of the existing construct (Discussion: pattern matching versus switch statement #4944)when
clause added toswitch
cases.And, for records:
record
keyword necessarywith
expressions (Proposal: "with" expressions for record types #5172)Implementation status of prototype port
Making the extension of
switch
backward-compatibledefault
which is always the lastresort.
resolved (Discussion: pattern matching versus switch statement #4944). In the draft spec,
a conversion will be applied on the
case
s, not on the control-expression unilaterally.Instead of converting only to
swithable
types, eachcase
arm will consider any conversions that allow thecase
to be applied.Any given conversion would be applied at most once.
goto case
statement is extended to allow any expression as its argument.Expression form of multi-arm pattern matching (#5154)
There is no
default
here, so cases are handled strictly in order.I propose the spec require that the compiler "prove" that all cases are handled
in a
match
expression using not-yet-specified rules. Writing those rulesis an open work item, but I imagine it will require the compiler to build
a decision tree and check it for completeness. That will also be needed to
implement checks that no case is subsumed by a previous case, which will
cause a warning (for
switch
) or error (formatch
).With-expressions (#5172)
The latter is translated into
We know how to do this for record types (because the language specifies the
mapping between constructor parameters and properties). We're examining how
to extend it to more general types.
To support inheritance, rather than directly using the constructor (as above) the generated code will
invoke a compiler-generated (but user-overridable) factory method.
Draft approach for algebraic data types
None of these classes would be permitted to be extended elsewhere.
a
match
expression that handles bothBinary
andConstant
caseswould not need a
*
(default) case, as the compiler can prove itis complete.
Remaining major issues
match
is completecase
is subsumed by a previouscase
with
expressions to non-record types?The text was updated successfully, but these errors were encountered: