On Saturday, August 27, 2016 at 3:41:34 PM UTC+8, T L wrote: > > > > On Saturday, August 27, 2016 at 1:36:53 PM UTC+8, Ian Lance Taylor wrote: >> >> On Fri, Aug 26, 2016 at 9:46 PM, T L <tapi...@gmail.com> wrote: >> > >> >> "You are suggesting that there is an extra rule to forbids converting >> []T1 >> >> to >> > []T2 when T1 and T2 have the same underlying representation." >> > >> > No. I understand []T1 can't be converted to []T2 when T1 and T2 have >> > different underlying representation. >> > >> > Ok, the alternative of my question is: why []T2 and []T1 have different >> > underlying representations when T2 and T1 have the same underlying >> > representation? >> >> They don't. >> >> If T2 and T1 have the same underlying representation, then []T2 and >> []T1 have the same underlying representation. >> >> >> >> "despite the overall prohibition on converting []T1 to >> > []T2, you are permitted to convert them exactly when T1 and T2 have >> > the same underlying representation. That rule is much more complex >> > than the current rule. It means that people reading Go code have to >> > understand when T1 and T2 have the same representation." >> > >> > So you mean there is no implementation obstacles to allow converting >> []Age >> > to []int? >> >> That is correct. >> >> >> > The prohibition is just to make people less confused. >> >> I would say that it is to make the language simpler. There are fewer >> things that people learning the language need to understand. >> >> >> > But the current prohibition make me confused, may I am not a typical >> gopher. >> >> Why does it make you confused? >> >> On a 64-bit system, the types "int" and "int64" have the same >> representation. They are both 64-bit signed integers. Does it >> confuse you that Go rejects >> >> var v int = int64(1) >> > > I don't think an int64 value can be converted to an int value is for they > have the same underlying type. > In fact, an int8 value can also be converted to an int value. > "Number values can be converted to values of other number types" is > totally an exception for the conversion rule. > This has nothing related to the underlying types. >
And another exception for the conversion rule is: 1. string values can be converted []byte values and vice versa. 2: string values can be converted []rune values and vice versa. For almost every basic rule in goalng, there are some exceptions. This is my impression for golang syntax rules. > > >> >> ? >> >> If that does not confuse you, then the fact Go does not permit >> assigning from []Age to []int should not confuse you. It is the same >> kind of thing: in Go, different types are different. >> >> Ian >> > -- 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.