[Proposal]: Static abstract members in interfaces
# Static abstract members in interfaces * [x] Proposed * [ ] Prototype: Not Started * [ ] Implementation: Not Started * [ ] Specification: Not Started Speclet: https://github.com/dotnet/csharplang/blob/main/proposals/csharp-11.0/static-abstracts-in-interfaces.md # Summary An interface is allowed to specify abstract static members that implementing classes and structs are then required to provide an explicit or implicit implementation of. The members can be accessed off of type parameters that are constrained by the interface. # Motivation [motivation]: #motivation There is currently no way to abstract over static members and write generalized code that applies across types that define those static members. This is particularly problematic for member kinds that *only* exist in a static form, notably operators. This feature allows generic algorithms over numeric types, represented by interface constraints that specify the presence of given operators. The algorithms can therefore be expressed in terms of such operators: ``` c# // Interface specifies static properties and operators interface IAddable<T> where T : IAddable<T> { static abstract T Zero { get; } static abstract T operator +(T t1, T t2); } // Classes and structs (including built-ins) can implement interface struct Int32 : …, IAddable<Int32> { static Int32 I.operator +(Int32 x, Int32 y) => x + y; // Explicit public static int Zero => 0; // Implicit } // Generic algorit
Posted by MadsTorgersen on Feb 12, 2021, 8:07 PM
Tags
Related issues
- [Meta] Feedback on granular control over Copilot changes
- unexpected status 401 Unauthorized issue
- [MODEL] Measurable quality regression in Claude generation 5 (Fable 5 / Opus 5 / Sonnet 5): worse nonsense detection, ~2x verbosity, under-disclosed model fallb
- [CRITICAL] Subagent spawning and subagent pattern bugs trigger infinite recursion, infinite token usage, grossly inefficient token usage, and lost accumulated s
- Video stops playing after some minutes
- [MODEL] Claude verbose code comments by default — ignores instructions to stop.
Raise real-world problems, find people facing the same issue, and discuss solutions.3,000 issues0 comments
github (Software)
[Meta] Feedback on granular control over Copilot changes
unexpected status 401 Unauthorized issue
[MODEL] Measurable quality regression in Claude generation 5 (Fable 5 / Opus 5 / Sonnet 5): worse nonsense detection, ~2x verbosity, under-disclosed model fallb
[CRITICAL] Subagent spawning and subagent pattern bugs trigger infinite recursion, infinite token usage, grossly inefficient token usage, and lost accumulated s
Video stops playing after some minutes
[MODEL] Claude verbose code comments by default — ignores instructions to stop.
Scope Codex VS Code chats to the current workspace/project
Update on "Co-authored-by: Copilot" in commit messages
[Proposal]: Static abstract members in interfaces
# Static abstract members in interfaces * [x] Proposed * [ ] Prototype: Not Started * [ ] Implementation: Not Started * [ ] Specification: Not Started Speclet: https://github.com/dotnet/csharplang/blob/main/proposals/csharp-11.0/static-abstracts-in-interfaces.md # Summary An interface is allowed to specify abstract static members that implementing classes and structs are then required to provide an explicit or implicit implementation of. The members can be accessed off of type parameters that are constrained by the interface. # Motivation [motivation]: #motivation There is currently no way to abstract over static members and write generalized code that applies across types that define those static members. This is particularly problematic for member kinds that *only* exist in a static form, notably operators. This feature allows generic algorithms over numeric types, represented by interface constraints that specify the presence of given operators. The algorithms can therefore be expressed in terms of such operators: ``` c# // Interface specifies static properties and operators interface IAddable<T> where T : IAddable<T> { static abstract T Zero { get; } static abstract T operator +(T t1, T t2); } // Classes and structs (including built-ins) can implement interface struct Int32 : …, IAddable<Int32> { static Int32 I.operator +(Int32 x, Int32 y) => x + y; // Explicit public static int Zero => 0; // Implicit } // Generic algorit
Comments (0)
No comments yet. Start the discussion.