Polymorphic Numerics on .Net and In C#

后端 未结 3 919
耶瑟儿~
耶瑟儿~ 2021-01-14 13:05

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

3条回答
  •  萌比男神i
    2021-01-14 13:18

    The csharp language team is already looking into this. If you want a view onto the future of type classes in C# start reading at

    https://github.com/dotnet/csharplang/issues/164

    It seems to have the support of Mads Torgesson so it's not just a random post by a wandering Haskell fanboy.

    The example given of a typeclass or shape in C# land is

    public shape SGroup
    {
        static T operator +(T t1, T t2);
        static T Zero { get; }
    }
    

    notice this is not like an interface. It is declaring static method that belong to SGroup. Read on for more details and discussion.

提交回复
热议问题