On Saturday, September 8, 2018 at 11:58:46 PM UTC-4, Robert Engels wrote:
>
> For the math operator, since Go already doesn’t do automatic numeric
> conversions, all of the operators are almost trivially implemented as
> methods, e.g. operator + is
>
> pseudo generic interface - not really required
>
> type PlusOperator<type A> interface {
> Plus(A) A
> }
>
This generic interface does not capture the + operator. The spec says that
the the operands and result of + are all the same type. Your interface is
satisfied by any type B with a method Plus(A) A. Types A and B do not have
to be the same.
> type MyStruct struct {
> }
> func (MyStruct) Plus(other MyStruct) MyStruct {
> …
> }
>
but also
type MyOtherStruct struct{}
func (MyOtherStruct) Plus(other MyStruct) MyStruct {
}
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.