NewThing[int, int]()  returns  a map[int]int, and therefore that's the type 
of MySet in func runInt.

You can think of NewThing[T1, T2] as a family of functions, like

func NewThing_int_int() map[int]int { ... }
func NewThing_int_byteslice() map[int][]byte { ... }
... etc

On Wednesday, 15 December 2021 at 17:01:41 UTC seank...@gmail.com wrote:

> when writing type parameterized code, it has to work with anything that 
> could be passed to it.
> but once instantiated, the type is known and it can be used with its 
> concrete type
>
> like `map` can be thought of as  declared to be `map[comparable]any`
> but when you use it, the type is always known, eg. `map[string]int`
> On Wednesday, December 15, 2021 at 5:39:39 PM UTC+1 Johannes Kohnen wrote:
>
>> Hello folks, 
>>
>> I've stumbled over a thing and I don't understand if what I've found is 
>> intentionally possible by design...
>>
>> https://go.dev/play/p/SIxOV1FnTzX?v=gotip 
>>
>> Why can I compare int with == when it was instantiated from the "any" 
>> type parameter? 
>>
>> The origin of my question is my implementation of a left right map which 
>> I've ported to generics.  While doing so I've uncovered a couple bugs in 
>> Jetbrains GoLand and reported them.  Except this one, because I've 
>> overlooked it and I now am confused:
>>
>>
>> https://github.com/jwkohnen/lrmap/blob/a6b9a6715069a7ad24de7cf84fe949dd7f194c0a/lrmap_test.go#L26
>>
>> In this line I compare two int values with !=, and this code compiles. 
>> Though, those value types were instantiated from the "any" type 
>> constraint.  GoLand reports an error in that line "Invalid operation: _v != 
>> v (the operator != is not defined on V)".
>>
>> From my reading of the generics proposal GoLand is right, but the 
>> compiler says otherwise.  How exactly are the operations that are defined 
>> on an "any" type inferred?
>>
>> Sorry if the answer is right there in the proposal; my reading 
>> comprehension fluctuates wildly these days. 
>>
>> Cheers,
>> Johannes
>>
>

-- 
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/efea2fcc-c0cc-4228-9f81-36b0435c4c8bn%40googlegroups.com.

Reply via email to