proposal: sum types as a non-interface union type
This is an issue to discuss yet another form of sum type to Go. This is not a full proposal, and not a language change that I expect will be adopted in the near future. I am filing this issue as a point of reference to discuss this particular approach. A sum type, tagged union, variant, variant record, choice type, discriminated union, disjoint union, or coproduct is a type which can hold a value of one of a fixed set of types. (Thanks [Wikipedia](https://en.wikipedia.org/wiki/Tagged_union) for the list.) Rust calls these enums, which means that when someone says Go should support "enums" they might be asking for a C-style enumeration of integers or a Rust-style enumeration of types. I posit that most people who want this feature in Go are looking for something along the lines of a Rust enum: https://doc.rust-lang.org/book/ch06-01-defining-an-enum.html To guide what follows, I'm going to also propose a few motivating examples which any design should support well. 1. A Direction type holding one of four cardinal directions: North, South, East, and West. 2. A Maybe type which either holds a value of some type or nothing. 3. An IP type holding either a `[4]byte` IPv4 address or a `[16]byte` IPv6 address. ### A digression: Can we just use interfaces? Many proposals for sum types in Go aim to extend interface types to cover this case. Since interfaces already support listing a set of type variants for use in type constraints, it's tempting to say that we could just permit so
Posted by neild on Dec 18, 2025, 10:03 PM
Tags
Related issues
- some bike vendor told me that the biggest problem with regular to ebike conversion was that regular bike frames were not strong enough to...
- I think of this as the kiosk economy.
- What a goofy comment.
- There's lots of evidence for positive influences of Caffeine on the body (some negative as well), especially the brain.
- Compose support in WSLc
- [RFC] Roadmap to v2.0
Raise real-world problems, find people facing the same issue, and discuss solutions.2,000 issues0 comments
support (Other)
some bike vendor told me that the biggest problem with regular to ebike conversion was that regular bike frames were not strong enough to...
I think of this as the kiosk economy.
What a goofy comment.
There's lots of evidence for positive influences of Caffeine on the body (some negative as well), especially the brain.
Compose support in WSLc
[RFC] Roadmap to v2.0
[Feature]: Add TurboQuant Support for KV Cache Quantization
Support for AGENTS.md and .agents/skills/, the community has been asking since August 2025
proposal: sum types as a non-interface union type
This is an issue to discuss yet another form of sum type to Go. This is not a full proposal, and not a language change that I expect will be adopted in the near future. I am filing this issue as a point of reference to discuss this particular approach. A sum type, tagged union, variant, variant record, choice type, discriminated union, disjoint union, or coproduct is a type which can hold a value of one of a fixed set of types. (Thanks [Wikipedia](https://en.wikipedia.org/wiki/Tagged_union) for the list.) Rust calls these enums, which means that when someone says Go should support "enums" they might be asking for a C-style enumeration of integers or a Rust-style enumeration of types. I posit that most people who want this feature in Go are looking for something along the lines of a Rust enum: https://doc.rust-lang.org/book/ch06-01-defining-an-enum.html To guide what follows, I'm going to also propose a few motivating examples which any design should support well. 1. A Direction type holding one of four cardinal directions: North, South, East, and West. 2. A Maybe type which either holds a value of some type or nothing. 3. An IP type holding either a `[4]byte` IPv4 address or a `[16]byte` IPv6 address. ### A digression: Can we just use interfaces? Many proposals for sum types in Go aim to extend interface types to cover this case. Since interfaces already support listing a set of type variants for use in type constraints, it's tempting to say that we could just permit so
Comments (0)
No comments yet. Start the discussion.