On Thu, Jan 6, 2022 at 1:58 PM tapi...@gmail.com <tapir....@gmail.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.
Note that this doesn't mean the spec is wrong - it can also mean the
compiler is wrong.


>
> 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 types*
>> 3. "interface { int; any }" is an *intersection* of *specific types*
>>
>> You 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+unsubscr...@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
> <https://groups.google.com/d/msgid/golang-nuts/e43a60ad-d812-418d-97e1-966fd3bcf61en%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAEkBMfGtMPq0OPd%2BnSz7Hok_T_tCH1f1Axo1dqn2eezKH0LhJA%40mail.gmail.com.

Reply via email to