Replies: 4 comments 2 replies
-
The delegate type is quite a pitfall in the .NET type system. There have been several ideas to improve it, for example, something like |
Beta Was this translation helpful? Give feedback.
-
after reading this
i was thinking a bit about this and have and idea that maybe is a bit crazy but whatever, since its discussion just spitballing here. Do you recall proposal to allow If i remember correctly |
Beta Was this translation helpful? Give feedback.
-
Regarding lambda natural types, I like it conceptually, as well as the conversion from lambdas and method groups to My concern, as mentioned, is specifically in the ability to declare an inferred local of a lambda, and the propensity of the inferred type being "wrong". My gut feeling is that where the compiler will infer that the lambda type should be My bigger concern is if that feature is extended beyond In both cases I believe the language, by adopting local inference of lambdas, will encourage developers to use them and in those cases where the lambda type is incompatible the developer will be more likely to take the easy way out taking another delegate instance to the method group of the incompatible delegate's `Invoke' method, incurring a second allocation and double delegate invocation. That second delegate also breaks reference equality for all of those APIs that expect it, like event handlers, where the compiler-chosen delegate type will never be compatible. To wrap it up, I believe that the ASP.NET use cases are satisfied without needing to extend natural lambda types to local variable inference. If the developer really wants to declare a local identifier for their routing function they can use a local function instead and pass the method group of that local function to the method. That's not to say that I don't like the idea of local lambda inference; I really do. But I'd rather evaluate that along with whatever runtime or language changes can support equivalence of delegate types based on signature and without the potential of that effort creating ambiguities or breaking changes in the future. |
Beta Was this translation helpful? Give feedback.
-
Can this delegate synthesizer be used for a hypothetical |
Beta Was this translation helpful? Give feedback.
-
https://github.com/dotnet/csharplang/blob/master/meetings/2021/LDM-2021-03-03.md
Agenda:
Beta Was this translation helpful? Give feedback.
All reactions