[go-nuts] Re: Discriminated Unions and Enums Example

2025-09-03 Thread Cliff
I got hit by a car last night. As I was sitting in the emergency room I realized the answer to Russ Cox's 2011 riddle https://groups.google.com/g/golang-nuts/c/0bcyZaL3T8E - you disambiguate as you're placing the item in the sum-type/box. type RW union { io.Reader io.Writer } mean? Or is it d

[go-nuts] Re: Discriminated Unions and Enums Example

2025-09-03 Thread Sandesh Gade
First of all, thank you for your effort into this! Impressive stuff. I am not a compiler expert, but the repo made it easier to understand the ideas you are talking about for someone like me. That being said, my following questions are a step towards understanding what is and isn't possible in

Re: [go-nuts] Re: Discriminated Unions and Enums Example

2025-09-03 Thread Cliff
Thanks for engaging. It was a lot of work. Per observations from 2011, interfaces in discriminated unions creates a mess. This implementation avoids that mess by disallowing them. Interfaces are extremely good at providing polymorphism for behaviors. Sum types/Discriminated unions serve a diffe

Re: [go-nuts] Re: Discriminated Unions and Enums Example

2025-09-02 Thread 'Axel Wagner' via golang-nuts
FWIW you can model a sum as a product plus a tag. That is, you can implement Maybe[T] = None | Some T match m { case None: // do thing case Some v: // do thing with v } as type Maybe[T any] struct { Case int // 0 or 1 None struct{} Some T } switch m.Case { case 0: // do th

Re: [go-nuts] Re: Discriminated Unions and Enums Example

2025-09-02 Thread 'Axel Wagner' via golang-nuts
On Tue, 2 Sept 2025 at 12:56, Cliff wrote: > From an implementation, language theory, and sanity point of view: putting > non-concrete types in a sum type won't work. If the design principles of go > demand interfaces in sum types, they will never be workable. Why not? In a union they don't wor

Re: [go-nuts] Re: Discriminated Unions and Enums Example

2025-09-02 Thread 'Axel Wagner' via golang-nuts
Hi, On Tue, 2 Sept 2025 at 00:48, Jason E. Aten wrote: > I'm neutral. > > + I like the exhaustiveness checking this enables. > […] > _ what happens when interfaces are choices inside a box? Go values > orthogonality and composability, so this would be a natural thing > for a developer to do. >

Re: [go-nuts] Re: Discriminated Unions and Enums Example

2025-09-02 Thread 'Axel Wagner' via golang-nuts
I should proof-read *before* hitting send: On Tue, 2 Sept 2025 at 11:00, Axel Wagner wrote: > It seems most likely (based on statements by the Go team) that we would > not want to add a new concept that has this much semantic overlap with > `interface{ a | b | c }`. But if we did that, the resul

[go-nuts] Re: Discriminated Unions and Enums Example

2025-09-02 Thread Stephen Illingworth
On Monday, 1 September 2025 at 23:47:50 UTC+1 Jason E. Aten wrote: - I don't like there being a new way to return an error, in effect hiding the fact that an error was returned inside a box. Having multiple return values with one of them being an error has become idiomatic, and I find this helps

[go-nuts] Re: Discriminated Unions and Enums Example

2025-09-01 Thread Jason E. Aten
I'm neutral. + I like the exhaustiveness checking this enables. + I like the potential for efficiency if only one of the union types needs to be allocated and there are a large number of possibilities. - I don't like the re-use of the type switch because it hurts the readability in that curre