Thanks! :) On Sunday, February 18, 2018 at 3:11:45 PM UTC-5, Krzysztof Kowalczyk wrote: > > I'm far from the expert on the spec but the behavior seems to follow the > rules. > > https://golang.org/ref/spec#Arithmetic_operators > > "Arithmetic operators apply to numeric values and yield a result of the > same type as the first operand." > > myInt + myInt returns myInt because it's the type of first operand. > > Is myInt a "numeric value"? > > https://golang.org/ref/spec#Type_declarations > > "A type definition creates a new, distinct type with the same underlying > type <https://golang.org/ref/spec#Types> and operations as the given > type, and binds an identifier to it." > > myInt is a distinct type from int, but it has the same underlying type and > is therefore "numeric value". > > > > On Sunday, February 18, 2018 at 11:30:58 AM UTC-8, Bill Wood wrote: >> >> Thanks. Why is the plus operator defined on myInt? Or if it simply >> treats a myInt as an int, why isn't the result an int? >> >> Sorry if this is a stupid question; I think either there is something >> deeper to this or else the arithmetic operators just have a special >> processing for this case. >> >> On Sunday, February 18, 2018 at 2:16:17 PM UTC-5, Jan Mercl wrote: >>> >>> On Sun, Feb 18, 2018 at 8:06 PM Bill Wood <wpwo...@gmail.com> wrote: >>> >>> > I thought that the plus operator would return an int, not a myInt. >>> >>> expr1 + expr2 works iff types of expr1 and expr2 are the same and the >>> result has the same type as both of the operands. Analogically for the >>> subtraction, multiplication and division operations. >>> >>> -- >>> >>> -j >>> >>
-- 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.