Re: [go-nuts] Re: Question about casting

2018-02-18 Thread Bill Wood
ype 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 "num

Re: [go-nuts] Re: Question about casting

2018-02-18 Thread Bill Wood
. 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 > > 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 th

[go-nuts] Re: Question about casting

2018-02-18 Thread Bill Wood
s interface{} = res; // no cast needed, see above > return ires > } > > Hope this clarifies the typing. > > Aside: if you come from C++, aliasing interface{} as any might feel > comfortable, but that's not a good Go style. > > > On Saturday, February 17, 2018 at

[go-nuts] Question about casting

2018-02-17 Thread Bill Wood
HI, Go newbie here... not sure if this is a dumb question or not :) I have a simple program: package main import "fmt" type any interface{} type myInt int func plus(a, b any) any { return a.(myInt) + b.(myInt) } func main() { s := plus(myInt(3), myInt(2)) fmt.Printf("%v, %T\n", s, s) } Outp