Re: [go-nuts] [generics] the empty type list

2020-06-18 Thread jimmy frasche
I think I'm missing something. How is nil not an inhabitant? On Thu, Jun 18, 2020 at 6:48 PM Bryan C. Mills wrote: > > On Thu, Jun 18, 2020 at 4:19 PM 'Axel Wagner' via golang-nuts > wrote: >> >> Addendum: In Go, every type needs to be inhabited by at least one value - >> it's zero value. And

Re: [go-nuts] [generics] the empty type list

2020-06-18 Thread 'Bryan C. Mills' via golang-nuts
On Thu, Jun 18, 2020 at 4:19 PM 'Axel Wagner' via golang-nuts < golang-nuts@googlegroups.com> wrote: > Addendum: In Go, every type needs to be inhabited by at least one value - > it's zero value. And we already have a type that can take *exactly* one > value, namely struct{}. > That is true, but

Re: [go-nuts] [generics] the empty type list

2020-06-18 Thread jimmy frasche
The constraint can't be used for phantom types. If C is an interface with an empty type list and P is given by type P(type T C) struct{} you can't instantiate P because no type can satisfy C. C is not the type with 0 inhabitants: it's a constraint on types that cannot be satisfied. I don't

Re: [go-nuts] [generics] the empty type list

2020-06-18 Thread 'Axel Wagner' via golang-nuts
Addendum: In Go, every type needs to be inhabited by at least one value - it's zero value. And we already have a type that can take *exactly* one value, namely struct{}. On Thu, Jun 18, 2020, 22:13 Axel Wagner wrote: > These arguments would be more convincing, if Go wouldn't already reject >

Re: [go-nuts] [generics] the empty type list

2020-06-18 Thread 'Axel Wagner' via golang-nuts
These arguments would be more convincing, if Go wouldn't already reject interfaces impossible to implement: https://play.golang.org/p/dYm8js26qml On Thu, Jun 18, 2020, 17:26 Jesper Louis Andersen < jesper.louis.ander...@gmail.com> wrote: > It is a type which cannot be inhabited by a term. These

Re: [go-nuts] [generics] the empty type list

2020-06-18 Thread Jesper Louis Andersen
It is a type which cannot be inhabited by a term. These exist and often have uses. As Bryan wrote they also completes the type lattice, so rejecting them is often a lot of work for little gain. If you want examples, look up phantom types, where an uninhabited type is used as a tag for ensuring

Re: [go-nuts] [generics] the empty type list

2020-06-18 Thread 'Bryan C. Mills' via golang-nuts
An empty intersection of type lists cannot be instantiated with any actual type, but if type-list interfaces could eventually be used as run-time types (as suggested in https://golang.org/design/go2draft-type-parameters#type-lists-in-interface-types), then the interface with an empty

Re: [go-nuts] [generics] the empty type list

2020-06-17 Thread Ian Lance Taylor
On Wed, Jun 17, 2020 at 4:33 PM jimmy frasche wrote: > > If I merge the two examples I still get an error > https://go2goplay.golang.org/p/TNYLDLokGCQ > > prog.go2:21:2: int does not satisfy Z (int not found in ⊥) I think that may be a bug in the type checker, which may not be quite updated to

Re: [go-nuts] [generics] the empty type list

2020-06-17 Thread jimmy frasche
I think that second error is a bug. I would expect that case to be the same as if I wrote a type list that was just int (and hence not the empty type list). On Wed, Jun 17, 2020 at 4:33 PM jimmy frasche wrote: > > If I merge the two examples I still get an error >

Re: [go-nuts] [generics] the empty type list

2020-06-17 Thread jimmy frasche
If I merge the two examples I still get an error https://go2goplay.golang.org/p/TNYLDLokGCQ prog.go2:21:2: int does not satisfy Z (int not found in ⊥) On Wed, Jun 17, 2020 at 4:24 PM Ian Lance Taylor wrote: > > On Wed, Jun 17, 2020 at 3:52 PM jimmy frasche wrote: > > > > The only case I mean

Re: [go-nuts] [generics] the empty type list

2020-06-17 Thread Ian Lance Taylor
On Wed, Jun 17, 2020 at 3:52 PM jimmy frasche wrote: > > The only case I mean is when the intersection of the type lists is ∅. > That's easy to check and always wrong afaict. Unfortunately I don't think it's that simple. type MyInt int type I1 interface { type int } type I2 interface {

Re: [go-nuts] [generics] the empty type list

2020-06-17 Thread jimmy frasche
The only case I mean is when the intersection of the type lists is ∅. That's easy to check and always wrong afaict. On Wed, Jun 17, 2020 at 3:47 PM Ian Lance Taylor wrote: > > On Wed, Jun 17, 2020 at 1:09 PM jimmy frasche wrote: > > > > This isn't a bug per se, but I can file one if requested.

Re: [go-nuts] [generics] the empty type list

2020-06-17 Thread Ian Lance Taylor
On Wed, Jun 17, 2020 at 1:09 PM jimmy frasche wrote: > > This isn't a bug per se, but I can file one if requested. > > https://go2goplay.golang.org/p/AWynhg6ya7h > > Since embedding interfaces with type lists uses the intersection of > the items in the type list, it's possible to create an