Re: [go-nuts] [generics] cannot use generic type list.Element(type TElem) without instantiation

2020-07-01 Thread Ian Lance Taylor
On Wed, Jul 1, 2020 at 8:22 PM Andrey T.  wrote:
>
> continuation question -- does `type intElement list.Element(int)` introduce a 
> new type just like `type myInt int` does? If so, in a previous example, these 
> 2 maps are not of the same type, am I right?

Yes, "type intElement list.Element(int)" introduces a new type.  You
can avoid introducing a new type by using a type alias: "type
intElement = list.Element(int)".

Ian


> On Wednesday, July 1, 2020 at 10:50:07 AM UTC-6, Ian Lance Taylor wrote:
>>
>> On Wed, Jul 1, 2020 at 9:39 AM  wrote:
>> >
>> > Is this expected?
>> >
>> > import "list" // for 'std' list.go2
>> >
>> > func main() {
>> > type intElement list.Element(int)
>> > _ = make(map[int]intElement) // ok: compiles
>> >
>> > // nok
>> > _ = make(map[int]list.Element(int)) // cannot use generic type 
>> > list.Element(type TElem) without instantiation
>> > }
>> >
>> > I don't think it is, but in case it is, how would I instantiate a 
>> > make(map[int]intElement) without having to typedef a generic type before.
>>
>> From the parser's perspective the argument to make is an expression,
>> so in this case you need parentheses to keep this from looking like a
>> type conversion.
>>
>> make(map[int](list.Element(int)))
>>
>> 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.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/golang-nuts/651e60c9-323f-481a-8eb1-a15e20e0f68do%40googlegroups.com.

-- 
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/CAOyqgcV48UThBA4jjDtDU%2Bgz3LPOKnU3VEqCAR6vwH80oVA%3DpQ%40mail.gmail.com.


Re: [go-nuts] [generics] cannot use generic type list.Element(type TElem) without instantiation

2020-07-01 Thread Andrey T.
Ian,

continuation question -- does `type intElement list.Element(int)` introduce 
a new type just like `type myInt int` does? If so, in a previous example, 
these 2 maps are not of the same type, am I right?

Thank you very much,
  Andrey

On Wednesday, July 1, 2020 at 10:50:07 AM UTC-6, Ian Lance Taylor wrote:
>
> On Wed, Jul 1, 2020 at 9:39 AM > 
> wrote: 
> > 
> > Is this expected? 
> > 
> > import "list" // for 'std' list.go2 
> > 
> > func main() { 
> > type intElement list.Element(int) 
> > _ = make(map[int]intElement) // ok: compiles 
> > 
> > // nok 
> > _ = make(map[int]list.Element(int)) // cannot use generic type 
> list.Element(type TElem) without instantiation 
> > } 
> > 
> > I don't think it is, but in case it is, how would I instantiate a 
> make(map[int]intElement) without having to typedef a generic type before. 
>
> From the parser's perspective the argument to make is an expression, 
> so in this case you need parentheses to keep this from looking like a 
> type conversion. 
>
> make(map[int](list.Element(int))) 
>
> 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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/651e60c9-323f-481a-8eb1-a15e20e0f68do%40googlegroups.com.


Re: [go-nuts] [generics] cannot use generic type list.Element(type TElem) without instantiation

2020-07-01 Thread Ian Lance Taylor
On Wed, Jul 1, 2020 at 9:39 AM  wrote:
>
> Is this expected?
>
> import "list" // for 'std' list.go2
>
> func main() {
> type intElement list.Element(int)
> _ = make(map[int]intElement) // ok: compiles
>
> // nok
> _ = make(map[int]list.Element(int)) // cannot use generic type 
> list.Element(type TElem) without instantiation
> }
>
> I don't think it is, but in case it is, how would I instantiate a 
> make(map[int]intElement) without having to typedef a generic type before.

>From the parser's perspective the argument to make is an expression,
so in this case you need parentheses to keep this from looking like a
type conversion.

make(map[int](list.Element(int)))

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


[go-nuts] [generics] cannot use generic type list.Element(type TElem) without instantiation

2020-07-01 Thread aurelien . rainone
Hi,

Is this expected? 

import "list" // for 'std' list.go2

func main() {
type intElement list.Element(int)
_ = make(map[int]intElement) // ok: compiles

// nok
_ = make(map[int]list.Element(int)) // cannot use generic type 
list.Element(type TElem) without instantiation
}

I don't think it is, but in case it is, how would I instantiate a 
make(map[int]intElement) 
without having to typedef a generic type before.

PS: i'm using the latest commit at the time of writing in the dev.go2go 
branch (6cf6bf162c)

-- 
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/45d75d8c-c424-4520-a24f-8cee64b63f88o%40googlegroups.com.