# Why I Gave Up on Smart Nil-Checking in My Programming Language

Original title: Union Types and Option Types

> Hacker News story 50342931 · language: en · submitted 2026-11-02
> Web version: https://zeli.app/story/50342931
> About this feed: https://zeli.app/llms.txt · Agent guide: https://zeli.app/skill.md

▲ 56 · by [g0xA52A2A](<https://news.ycombinator.com/user?id=g0xA52A2A>) · 💬 24
[original](<https://tibleiz.net/blog/2025-03-16-union-types-and-option-types.html>) · [HN discussion](<https://news.ycombinator.com/item?id=50342931>)

## Summary

After experimenting with union types in his low-level language Copper, the author settles on option types (T?) as a simpler alternative. He implements them by reserving a nil value per type, adds an 'as' operator for safe refinement, and tries compiler-inferred nil-checking like TypeScript's. Despite its benefits, he abandons the inferred approach due to two-pass loop analysis, poor genericity, and unpredictable edge cases, reverting to explicit refinement.

## Key quote

> Last but not least, it's a kind of black magic: the validity of the program depends on the power of the nil-checker.

## HN discussion (24 comments)

### [p1necone](<https://news.ycombinator.com/item?id=50360086>)

> 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](<https://news.ycombinator.com/item?id=50360271>)

> 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.

### [gnabgib](<https://news.ycombinator.com/item?id=50343387>)

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

---

## Cite

- Page: https://zeli.app/story/50342931
- Date: 2026-11-02
- Source: tibleiz.net (https://tibleiz.net/blog/2025-03-16-union-types-and-option-types.html)
- Hacker News: https://news.ycombinator.com/item?id=50342931

## Other languages

- zh: https://zeli.app/zh/story/50342931 · markdown: https://zeli.app/zh/story/50342931.md
- ja: https://zeli.app/ja/story/50342931 · markdown: https://zeli.app/ja/story/50342931.md
- ko: https://zeli.app/ko/story/50342931 · markdown: https://zeli.app/ko/story/50342931.md
- de: https://zeli.app/de/story/50342931 · markdown: https://zeli.app/de/story/50342931.md
- es: https://zeli.app/es/story/50342931 · markdown: https://zeli.app/es/story/50342931.md
- ru: https://zeli.app/ru/story/50342931 · markdown: https://zeli.app/ru/story/50342931.md
