No, the mistake is in your reading of the spec. You are complaining about this line:interface{ int; any } // no specific types (intersection is empty)The spec makes it clear that:1. "any" is short for "interface {}"2. "interface {}" has no specific types
On Thursday, January 6, 2022 at 8:35:06 PM UTC+8 Brian Candler wrote:No, the mistake is in your reading of the spec. You are complaining about this line:interface{ int; any } // no specific types (intersection is empty)The spec makes it clear that:1. "any" is short for "interface {}"2. "interface {}" has no specific typesI think your logic mistake here is that the operands of the union and intersection operations are type sets, instead of specific types.
On Thursday, January 6, 2022 at 9:40:52 PM UTC+8 tapi...@gmail.com wrote:On Thursday, January 6, 2022 at 8:35:06 PM UTC+8 Brian Candler wrote:No, the mistake is in your reading of the spec. You are complaining about this line:interface{ int; any } // no specific types (intersection is empty)The spec makes it clear that:1. "any" is short for "interface {}"2. "interface {}" has no specific typesI think your logic mistake here is that the operands of the union and intersection operations are type sets, instead of specific types.This conclusion is not very precise. More precisely, the operands of the union and intersection operationscould be either type set or specific types, but interface types don't participate in calculations of specific types.
--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/cda21095-d57e-4f9d-8853-4a6a7e683953n%40googlegroups.com.
I don't think your conclusion is right. Otherwise, the following code doesn't compile, but it does.type C interface{ int; any }
func f[T C](x byte) T {
return T(x)
}
On Thursday, January 6, 2022 at 8:35:06 PM UTC+8 Brian Candler wrote:No, the mistake is in your reading of the spec. You are complaining about this line:interface{ int; any } // no specific types (intersection is empty)The spec makes it clear that:1. "any" is short for "interface {}"2. "interface {}" has no specific types3. "interface { int; any }" is an intersection of specific typesYou are taking the intersection of the set of one type (int) with the empty set, and therefore the result is the empty set. Exactly as the comment says.On Thursday, 6 January 2022 at 11:47:52 UTC tapi...@gmail.com wrote:On Thursday, January 6, 2022 at 6:15:06 PM UTC+8 Brian Candler wrote:1. interface { a;b } is intersection. The "Intersection" between two sets means things which exist in both sets simultaneously.2. interface { a|b } is union. "Union" means a set of things which which exist in set A or set B.Quoting from the spec:"the predeclared type any is an alias for the empty interface.""interface{} // no specific types""For an interface with type elements, 𝑆 is the intersection of the specific types of its type elements."Can you see now?The explanation is as what I think.But what is your conclusion? Is it a mistake in spec?
--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/e43a60ad-d812-418d-97e1-966fd3bcf61en%40googlegroups.com.
I don't think your conclusion is right. Otherwise, the following code doesn't compile, but it does.type C interface{ int; any }
func f[T C](x byte) T {
return T(x)
}I agree that the compiler and spec seem to disagree here. It seems to me that by the spec, this should not be allowed, as C has no specific types.
On Thursday, 6 January 2022 at 17:13:38 UTC axel.wa...@googlemail.com wrote:I don't think your conclusion is right. Otherwise, the following code doesn't compile, but it does.type C interface{ int; any }
func f[T C](x byte) T {
return T(x)
}I agree that the compiler and spec seem to disagree here. It seems to me that by the spec, this should not be allowed, as C has no specific types.But is that true? "Type set" and "specific types" are two different concepts, and "specific types" are only required in certain contexts, which are called out in the spec.
It seems that function f[T C] will accept any type which is in the *type set* of C - is that not reasonable?
This does of course highlight how complex the language has become with the introduction of generics.
--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/6edaaaf6-87a8-4cb4-9015-8bb007a5d70cn%40googlegroups.com.
On Thu, Jan 6, 2022 at 8:59 AM 'Axel Wagner' via golang-nuts
<golan...@googlegroups.com> wrote:
>
> • From the definition of type elements, we can see that an embedded interface type is a type element. Therefore, `any` is a type element.
> • `any` is an alias for `interface{}`, therefore it is a type without any type elements, therefore the set of its specific types is empty ("For an interface with no type elements, 𝑆 is the empty set.").
> • `interface{ int; any }` is a type with two type elements. "For an interface with type elements, 𝑆 is the intersection of the specific types of its type elements.". Intersecting with an empty set (the specific types of `any`) gives an empty set
> • Therefore, the set of specific types of `interface{ int; any }` is the empty set.
That doesn't seem right. "any" is an interface type and writing
"interface { any }" just embeds the empty interface, which has no
effect.
InterfaceType = "interface" "{" { InterfaceElem ";" } "}" .
InterfaceElem = MethodElem | TypeElem .
MethodElem = MethodName Signature .
MethodName = identifier .
TypeElem = TypeTerm { "|" TypeTerm } .
TypeTerm = Type | UnderlyingType .
UnderlyingType = "~" Type .
The actual type set is hard to compute, in general, so using it to define the set of allowed operations on a type is impractical. The easier to calculate set of specific types was introduced, I believe, to fix this problem. It should always be a subset of the actual type set.
Is that necessarily true? The spec appears to have an example where the specific types are a superset of the type set:-----Examples of interfaces with their specific types:
...interface{ int; m() } // int (but type set is empty because int has no method m)-----
--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/c511e7f6-2ce3-4c69-af9c-50da95571837n%40googlegroups.com.
Thanks for raising this issue. This is clearly a bug in the spec, or at the very least "an imprecision". Hopefully this is better: https://go-review.googlesource.com/c/go/+/375799 .
--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/d6e91c64-7a8a-4bd2-912b-3f9a1cb7333an%40googlegroups.com.