-
Notifications
You must be signed in to change notification settings - Fork 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
[Proposal] Add interface hierarchy to primitive types #3423
Comments
Wrapping all of the primitive types with interface implementations would be a CLR concern, you could request that here: https://github.com/dotnet/runtime/issues However, doing so would have some big disadvantages. Calling a method through an interface like this requires boxing the value type which incurs an allocation on the heap, plus the virtual dispatch of calling the instance member on the interface. Generic specialization on structs may help to avoid some of this. The C# team is proposing solving these kinds of problems in a different way: #1711 |
Well, at least the team recognize the shortcoming and are working on at. Thanks for the issue# link. I heard of monoids before and had no idea what they were talking about, but I am beginning to understand. |
Nit: should be |
Then under |
|
A |
It is not just an artifact, it is a fundamental value of the It is something that would need to be understood and rationalized with these interfaces if they were ever to become a real thing. |
I like the idea that primitive types implement a set of standardized interfaces this could be useful in generic constraints.. ...but Difficult to known in advance, which interface hierachy is needed. |
You are right in that |
Is there a way to migrate the issue, or shall I close and re-post in the CLR hub? |
@ja72 You might want to read dotnet/runtime#14723 first. See also dotnet/runtime#25058 and dotnet/runtime#18244. |
Clsoing as duplicate of dotnet/runtime#14723 and other issues on dotnet/runtime |
The intent is to help with generic constrains, extension methods, and generally handling primitives types.
The specialized libraries can hook into this to defined other custom types that will play well within the existing framework
Additionally, it would make sense that arithmetic operators and comparisons be required to be implemented to create concrete types from the
INumeric
interface.The addition of the above interfaces and implementation with primitive types would make the CLR far more flexible and extensible for scientific computing applications. It would allow for more generic code writing such as:
and the compiler would know how to bind the arithmetic operators or do the implicit conversions (like from float to double) to make the code work without having to write different versions for different numeric types.
The text was updated successfully, but these errors were encountered: