Re: [go-nuts] Nillable basic types?

2024-03-21 Thread Mike Schinkel
Hi Axel, Thank you for that link. I had not seen it before, but it is rather insightful. -Mike On Wednesday, March 20, 2024 at 10:29:20 AM UTC-4 Axel Wagner wrote: FWIW I believe (as Brian sort of points out) this proposal is fully subsumed under #57644

Re: [go-nuts] Nillable basic types?

2024-03-20 Thread 'Axel Wagner' via golang-nuts
FWIW I believe (as Brian sort of points out) this proposal is fully subsumed under #57644 . Under that proposal, the proposed type `int | nil` would be spelled `interface{ int }`. The other syntactical constructs are, as far as I can tell, identical -

Re: [go-nuts] Nillable basic types?

2024-03-20 Thread Mike Schinkel
On Wednesday, March 20, 2024 at 5:47:00 AM UTC-4 Brian Candler wrote: If you change fundamental things like this in the language, then you'll suggesting turning Go into something that looks like Rust. In which case, you may as well just use Rust. Agreed. Which is why I was asking if using

Re: [go-nuts] Nillable basic types?

2024-03-20 Thread Mike Schinkel
On Wednesday, March 20, 2024 at 5:31:08 AM UTC-4 Brian Candler wrote: It's in the very first post that opened this thread, under the heading "## Summary". I did in-fact miss it. Thank you for pointing to it. -Mike -- You received this message because you are subscribed to the Google

Re: [go-nuts] Nillable basic types?

2024-03-20 Thread 'Brian Candler' via golang-nuts
I got the impression the proposal was motivated by scalars that did not currently allow `nil` values Under the heading "Alternatives and why they're bad" he describes some ways this is currently dealt with - such as the common idiom of returning or passing a pointer to a value, instead of a

Re: [go-nuts] Nillable basic types?

2024-03-20 Thread 'Brian Candler' via golang-nuts
On Wednesday 20 March 2024 at 09:01:43 UTC Mike Schinkel wrote: Your comments made me go back and read the whole thing, but I was unable to find a list of enumerated objectives, and I did not find the text you quoted. Did I miss it somehow? It's in the very first post that opened this

Re: [go-nuts] Nillable basic types?

2024-03-20 Thread Mike Schinkel
On Wednesday, March 20, 2024 at 4:14:27 AM UTC-4 Brian Candler wrote: When you say "var x NillableUint8" then you've just declared a variable of an interface type, and interface types are already nilable, so there's no need for "| nil" in the type! Well, I was thinking of 1.) explicitness

Re: [go-nuts] Nillable basic types?

2024-03-20 Thread 'Brian Candler' via golang-nuts
When you say "var x NillableUint8" then you've just declared a variable of an interface type, and interface types are already nilable, so there's no need for "| nil" in the type! https://go.dev/play/p/f54akG65qJ3 https://go.dev/play/p/Jmtlta0h9m9 // generic version It's a perfectly valid way

Re: [go-nuts] Nillable basic types?

2024-03-20 Thread Mike Schinkel
> On Mar 19, 2024, at 2:43 PM, Daniel Lepage wrote: > > I'm not proposing that *any* value be made nillable, I'm proposing the > explicit syntax > > var x uint8 | nil > > that would create a nillable uint8. A variable of type `byte` would still > only take up one byte; a variable of type

Re: [go-nuts] Nillable basic types?

2024-03-19 Thread Patrick Smith
On Tue, Mar 19, 2024 at 11:44 AM Daniel Lepage wrote: > I'm not proposing that *any* value be made nillable, I'm proposing the > explicit syntax > > var x uint8 | nil > > that would create a nillable uint8. A variable of type `byte` would still > only take up one byte; a variable of type `byte |

Re: [go-nuts] Nillable basic types?

2024-03-19 Thread Daniel Lepage
*From Jan Mercl: * > To represent all those values and the new possibility > of the value being nil, we need 257 distinct values. But that does not > fit 8 in bits anymore. However, changing the size and/or the bit > representation of such a variable is observable, making it not >

Re: [go-nuts] Nillable basic types?

2024-03-19 Thread Jeremy French
I understand the problem you are trying to solve, and it's valid, I think. But this solutions "feels" bad and very un-Go-like. Usable zero values is a feature in Go. Whether you agree with that or not, it's a selling feature of the language and clearly something that was/is important to the

Re: [go-nuts] Nillable basic types?

2024-03-18 Thread 'Brian Candler' via golang-nuts
I like Go because it's relatively simple and low-level, like C, except with things like garbage collection and channels integrated. If Go were to have "| nil" types then the internal representation of such variables would have to be something like this: type Maybe[T any] struct { Value T

Re: [go-nuts] Nillable basic types?

2024-03-18 Thread Jan Mercl
On Mon, Mar 18, 2024 at 4:41 AM Daniel Lepage wrote: > This change would be entirely backward-compatible ... Let's consider, for example, the type uint8, aka byte. A variable of type byte is specified* to occupy 8 bits of memory and has 256 possible values. To represent all those values and the

[go-nuts] Nillable basic types?

2024-03-17 Thread Daniel Lepage
Hey everyone, I've been thinking for a while now about the advantages of nillable types, especially for basic types, and I'm interested in making an official language proposal. I'd love to know what the rest of the community thinks about it, and if this discussion has been had before (I found