Proposal: deconstruction of formal parameters #153
Replies: 9 comments
-
Why restrict to records with one param only? The following looks doable as well:
|
Beta Was this translation helpful? Give feedback.
-
Because this will look terrible in Intellisense otherwise. |
Beta Was this translation helpful? Give feedback.
-
As a rule, Intellisense can show the deconstruction for nameless params.
the following signature will be shown in intellisene:
In some scenarios, the names in the deconstruction might be more meaningful than naming the record as a whole. With the above design, the API designer can hint the consumer how to construct the args. |
Beta Was this translation helpful? Give feedback.
-
What if I want to consume this from a language that doesn't know anything about nameless parameters? |
Beta Was this translation helpful? Give feedback.
-
Many of the new C# features will look odd for consumers from other languages, including tuples, ADTs, and so on. |
Beta Was this translation helpful? Give feedback.
-
Generally speaking we prefer to keep implementation details such as this out of the "header" of a method. |
Beta Was this translation helpful? Give feedback.
-
@gafter what about |
Beta Was this translation helpful? Give feedback.
-
I am very interested in trivial record types, but I find classical approach more readable.
|
Beta Was this translation helpful? Give feedback.
-
@orthoxerox The |
Beta Was this translation helpful? Give feedback.
-
Depends on #39. Copied from dotnet/roslyn#15111.
Trivial record types are a common pattern in functional languages, providing additional type safety over bare numbers or strings or tuples:
However, using them in C# requires additional deconstruction or constant member access:
I propose to allow positional deconstruction in method declarations.
Deconstructed parameters can lack their own names if they have only one parameter:
Deconstruction of types parameterized by deconstructible types, like
cc
inSendMail
above, is an open question:Perhaps it can be done rather straightforwardly for all monadic (LINQ-able) types.
Beta Was this translation helpful? Give feedback.
All reactions