Re: [go-nuts] [generics] type list should not pass newtypes

2020-06-28 Thread Ian Lance Taylor
On Sun, Jun 28, 2020 at 9:37 AM tdakkota wrote: > > When I say 'it's not Go-1like' I mean that MyInt type is not equal to int > type in Go1 type system. > reflect.DeepEqual(int(0), MyInt(0)) returns false. > Type assertion fails. > That's why I call it 'newtype'. > > But type lists with non-inter

Re: [go-nuts] [generics] type list should not pass newtypes

2020-06-28 Thread Viktor Kojouharov
These type lists that are used in generic interfaces are not sum types. they are there to allow restrictions on operators, since only base types have operators in go (and types which use them as underlying types inherit). You are thinking of sum types, which go does not have. On Sunday, June 28

Re: [go-nuts] [generics] type list should not pass newtypes

2020-06-28 Thread tdakkota
When I say 'it's not Go-1like' I mean that MyInt type is not equal to int type in Go1 type system. reflect.DeepEqual(int(0), MyInt(0)) returns false. Type assertion fails. That's why I call it 'newtype'. But type lists with non-interface types have a different logic. MyInt type is equal to int.

Re: [go-nuts] [generics] type list should not pass newtypes

2020-06-27 Thread Ian Lance Taylor
On Sat, Jun 27, 2020 at 3:06 PM tdakkota wrote: > > I think, if I want int/[]int, I should use int/[]int or just declare a domain > specific alias. > MyInt/[]MyInt should implement Lesser/Min/etc interface. It can declare > specific comparison rules. > > Min implementation can be like: https://g

Re: [go-nuts] [generics] type list should not pass newtypes

2020-06-27 Thread tdakkota
I think, if I want int/[]int, I should use int/[]int or just declare a domain specific alias. MyInt/[]MyInt should implement Lesser/Min/etc interface. It can declare specific comparison rules. Min implementation can be like: https://go2goplay.golang.org/p/Fgo2fJAlKXD (this code does not compile

Re: [go-nuts] [generics] type list should not pass newtypes

2020-06-27 Thread Ian Lance Taylor
On Sat, Jun 27, 2020 at 12:35 PM a b wrote: > > Newtype is a expression like > type MyInt int > > It's not the same type as int, so why it's permitted? > In Go1 you must perform explicit conversion. Because if you have a []MyInt, it would be nice to be able to pass that to a function like slices.