Re: [go-nuts] Nil could be the zero value for type variables

2022-06-10 Thread Will Faught
Thanks. I think these are more complicated and less consistent, since they require adding syntax for `_`, but I can see a similar motivation. On Sun, Jun 5, 2022 at 9:44 PM Nigel Tao wrote: > On Tue, May 31, 2022 at 1:39 AM Will Faught wrote: > >> Why not allow nil to be used as the zero value

Re: [go-nuts] Nil could be the zero value for type variables

2022-06-05 Thread Nigel Tao
On Tue, May 31, 2022 at 1:39 AM Will Faught wrote: > Why not allow nil to be used as the zero value for type variables, to fill > this gap? > > return nil // == V(nil) > See also: https://github.com/golang/go/issues/35966 https://github.com/golang/go/issues/19642 -- You received this message

Re: [go-nuts] Nil could be the zero value for type variables

2022-06-02 Thread 'Axel Wagner' via golang-nuts
This is increasingly off-topic (I don't have anything to add to the on-topic stuff itself), but. On Thu, Jun 2, 2022 at 11:03 AM Brian Candler wrote: > I wonder then why slice wasn't defined the same way - i.e. the zero value > of a slice could have been "empty slice". Today, empty slice and

Re: [go-nuts] Nil could be the zero value for type variables

2022-06-02 Thread Brian Candler
On Wednesday, 1 June 2022 at 08:49:50 UTC+1 axel.wa...@googlemail.com wrote: > Where confusion might arise is in the operations on nil. It's already >> weird that nil slices and zero-length slices are distinguishable: >> https://go.dev/play/p/6MVECg4onAk >> >> We'd then end up in the same

Re: [go-nuts] Nil could be the zero value for type variables

2022-06-01 Thread 'Axel Wagner' via golang-nuts
On Wed, Jun 1, 2022 at 9:05 AM Brian Candler wrote: > On Wednesday, 1 June 2022 at 02:19:43 UTC+1 Ian Lance Taylor wrote: > >> We could do that. The main concern is that "nil" is already >> overloaded, and people new to Go are frequently confused by it. See >> the FAQ entry

Re: [go-nuts] Nil could be the zero value for type variables

2022-06-01 Thread Brian Candler
On Wednesday, 1 June 2022 at 02:19:43 UTC+1 Ian Lance Taylor wrote: > We could do that. The main concern is that "nil" is already > overloaded, and people new to Go are frequently confused by it. See > the FAQ entry https://go.dev/doc/faq#nil_error . Adding more uses of > nil will increase the

Re: [go-nuts] Nil could be the zero value for type variables

2022-05-31 Thread Will Faught
Thanks for pointing out that section. I guess I'd forgotten this issue was discussed there. It looks like this exact approach (nil for all types) isn't listed there, but there's a similar one that adds nil to just type variables. Please add this one to your mental list! :) Fair enough about the

Re: [go-nuts] Nil could be the zero value for type variables

2022-05-31 Thread Ian Lance Taylor
On Mon, May 30, 2022 at 6:39 PM Will Faught wrote: > > Currently, if I understand correctly, there's no expression for the zero > value for a type variable: Thanks for the note. There is some discussion of this at

Re: [go-nuts] Nil could be the zero value for type variables

2022-05-30 Thread Will Faught
Right, I discussed that: Currently, if I understand correctly, the only way to do this is to declare > a variable, and return that: > var zeroValue V > return zeroValue On Mon, May 30, 2022 at 7:33 PM Bruno Albuquerque wrote: > This should work on your example: > > var zeroValue V > > On Mon,

Re: [go-nuts] Nil could be the zero value for type variables

2022-05-30 Thread Bruno Albuquerque
This should work on your example: var zeroValue V On Mon, May 30, 2022, 6:39 PM Will Faught wrote: > Hello, fellow Gophers! > > Currently, if I understand correctly, there's no expression for the zero > value for a type variable: > > type Map[K comparable, V any] struct { > ks []K > vs

[go-nuts] Nil could be the zero value for type variables

2022-05-30 Thread Will Faught
Hello, fellow Gophers! Currently, if I understand correctly, there's no expression for the zero value for a type variable: type Map[K comparable, V any] struct { ks []K vs []V } func (m Map[K, V]) Get(k K) V { for i, k2 := range m.ks { if k2 == k { return m.vs[i]