Opinion on possible need for Higher-Level Generics #1281
Replies: 5 comments
-
This is a prime case for what Shapes should be used for. |
Beta Was this translation helpful? Give feedback.
-
Some of Your problems could be solved by covariant return #49 |
Beta Was this translation helpful? Give feedback.
-
How is the current proposal for shapes insufficient for this? The proposal even includes an example that's very similar to yours (it's a group and not a ring, but I don't think that makes a difference). The only thing missing is (multiple) inheritance between shapes, which doesn't seem to be explicitly mentioned by the shapes proposal. But type classes, which form the basis of that proposal, support it. So I expect multiple inheritance of shapes will be supported. |
Beta Was this translation helpful? Give feedback.
-
I've run into this problem and I've made things work using extension methods. For example,
|
Beta Was this translation helpful? Give feedback.
-
See #110 for a proposal (with working prototype) that supports this. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Introduction / Motivation
I am currently re-visiting older code from a Mathematics-Library that I have written and I decided to update and refractor it.
However, I stumbled upon the following problem:
Imagine an abstract class representing an topological algebraic ring.
It would have to define an
0
-element, a1
-element and the operators+
and*
. It would look something along these lines:For now, everything seems more or less OK, doesn't it?
Now Imagine, you want to implement the following "inheritance tree"
You can imagine, how this can quickly go out of hands. Even more - it will be an utter nightmare, if you do not want only to implement such algebraic, topologic and analytic concepts in form of
double
-somethings (e.g.DoubleFunction
,DoublePolynomialRing
etc.) - but generic, so that types likeint
orComplex
could also be supported ....The implementatinos of the types described above would all look as follows:
What I wish for next Christmas (or earlier)
It would be fantastic to have some sort of generic concept, which allows the reference of the child type* in definitions. (With 'child type' I mean the type, which will implement the current one.)
One example could look as follows:
The keyword
child
would now represent the opposite ofbase
- in the sense that it refers to the type, which will implement the current one ...Of course, this would be highly complicated to implement in the CLR and the compiler pipeline, so I propose the following:
What do you think? Does C# need stuff like this?
Should it stay more to the "classical" OOP-Style?
Should it -as I think- provide a more functional type-definition system? (e.g. shapes, generic union types, recursive types, ....)
Please Discuss!
Beta Was this translation helpful? Give feedback.
All reactions