Union Types and Option Types (2025)

g0xA52A2A 61 points 27 comments November 02, 2026
tibleiz.net · View on Hacker News

Discussion Highlights (8 comments)

gnabgib

(2025) And about CopperLang (203 points, 3 days ago, 120 comments) https://news.ycombinator.com/item?id=50308754

direwolf20

i read Onion Types

p1necone

One simple but non obvious (at least to me) trick when implementing tagged unions: put the union discriminator/tag at the end , not the beginning - that way a pointer to a union is also a pointer to the value, no need to increment the pointer to point past the tag after discriminating.

ks2048

What is the best source for cross-language description of language features? Eg: “optional types”: which langs have them and how do they work? Same with “union types” etc.

cardboardguru

Swift has already answered all these questions.

jakobnissen

It seems bizarre to me that Copper includes Union types and then, for implementation reasons, does not include so many of its basic features, and even its basic properties. Like, what do you mean you can’t have three union members? And that the order of the union matters? These are some of the most useful properties of union types, and the arguments for what Copper did are weak sauce.

Panzerschrek

var value = maybeValue.notNil // I know what I'm doing How does it work exactly? Does it perform a runtime check, or just trusts the programmer?

Panzerschrek

> The option type, despite being simpler than union type introduces many new concepts and requires additional knowledge that make the language more complex. That's why I do such things in my language in a different way. Optional and union types are just library container classes. More methods may be added if necessary, internal layout may be changed, etc. without changing the language core itself. But in such an approach the language itself should provide necessary means allowing creation of such library abstractions.

Semantic search powered by Rivestack pgvector
3,874 stories · 35,194 chunks indexed