On Fri, Dec 14, 2018 at 11:00 AM <patrick.buche...@gmail.com> wrote: > > When programmers complain about the lack of generics in Go, a common > mitigation proposed is to use a interface. In many cases, it's possible to > find an operation common to all the types to be supported; in the worst case, > an empty interface can be used. > > This doesn't satisfy many Go programmers, so a proposal for generic types has > been made, containing the contract keyword: > > > contract Ordinal(t T) { > t < t > } > > > So a contract looks basically like an interface, which doesn't require a type > to implement a certain method, but to support the use of certain operations > on it. > > When I think of operations and types that apply to them in Go, the following > categories come to my mind: > > > Equality, expressed by == and !=, which is supported by most Go expressions. > +, which adds up numbers and concatenates strings. > Other operations for arithmetics and comparison: -, *, /, %, <, >, <=, >=. > Accessors and qualifiers: . and [] > > > Complaints about the lack of generics in Go are often heard from programmers > that want to implement numeric libraries. They basically want a type, which > support the operations of the first three categories, which are basically the > numeric types: integer, floating point and complex numbers. > > > So an abstract "numeric" or "number" type could eliminate a lot of the use > cases for contracts. Is this an option being considered? Or isn't there just > any benefit over using the double type for numeric computations?
I had the similar idea a while ago and wrote this up, but with contracts expressed as existing types instead of a numeric interface: https://gist.github.com/bserdar/8f583d6e8df2bbec145912b66a8874b3 There's been a lot of discussion about the generics proposal: https://github.com/golang/go/wiki/Go2GenericsFeedback > > > Patrick > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.