Note that there are some explanatory texts on larger screens.

plurals
  1. POPolymorphic Numerics on .Net and In C#
    primarykey
    data
    text
    <p>It's a real shame that in .Net there is no polymorphism for numbers, i.e. no INumeric interface that unifies the different kinds of numerical types such as bool, byte, uint, int, etc. In the extreme one would like a complete package of abstract algebra types.</p> <p>Joe Duffy has an article about the issue:</p> <p><a href="http://www.bluebytesoftware.com/blog/CommentView,guid,14b37ade-3110-4596-9d6e-bacdcd75baa8.aspx" rel="nofollow noreferrer">http://www.bluebytesoftware.com/blog/CommentView,guid,14b37ade-3110-4596-9d6e-bacdcd75baa8.aspx</a></p> <p>How would you express this in C#, in order to retrofit it, without having influence over .Net or C#?</p> <p>I have one idea that involves first defining one or more abstract types (interfaces such as INumeric - or more abstract than that) and then defining structs that implement these and wrap types such as int while providing operations that return the new type (e.g. Integer32 : INumeric; where addition would be defined as</p> <pre><code>public Integer32 Add(Integer32 other) { return Return(Value + other.Value); } </code></pre> <p>I am somewhat afraid of the execution speed of this code but at least it is abstract.</p> <p>No operator overloading goodness...</p> <p>Any other ideas?</p> <p>.Net doesn't look like a viable long-term platform if it cannot have this kind of abstraction I think - and be efficient about it.</p> <p>Abstraction is reuse.</p> <p>update:</p> <p>This is an example implementation type signature so far:</p> <pre><code>public struct Integer32 : INumeric&lt;Integer32, Int32&gt;, IOrder&lt;Integer32, Int32&gt; </code></pre> <p>Compensating for the lack of covariant return types.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload