Oriel — AI & technology worth noticing, every day.

Union Types and Option Types

Web page · https://tibleiz.net/blog/2025-03-16-union-types-and-option-types.html

First seen by Oriel on .

AI summary

This essay compares union and option types in Copper, describing a nil-as-reserved-value design and concluding that explicit refinement is preferable to automated nil analysis despite added complexity.

  • Copper’s general union implementation used tags, prohibited nested unions, made order significant, and disallowed compatibility between differently sized unions.
  • Option T? reserves one value in T, enabling efficient native C integration but preventing T?? and failing for types without a spare value.
  • Explicit refinement through as, or else, and notNil supports safe access, early returns, and cases the compiler cannot prove automatically.
  • Automated nil checking simplified common code but required loop analysis, interacted poorly with generics, missed some relationships, and increased compiler work by 5%.
  • Porting Copper, Clade, and the experimental decompiler showed option types can prevent nil dereferences and clarify intent, while exposing algorithms’ unverifiable invariants.

#copper #option types #type systems #compiler design

Generated by gpt-5.6-sol. Check the original for details.

Metric trends

Last 30 days · Up to 120 recorded samples per source and metric, with reposts kept separate · First and latest retained

Points

Score reported by the source.

  • Hacker News: 56, latest observation ; +50 over observed period since
  • Lobsters: 14, latest observation ; +12 over observed period since

Comments

Comment count reported by the source.

  • Hacker News: 24, latest observation ; +23 over observed period since
  • Lobsters: 4, latest observation ; +4 over observed period since

Aliases

SourceExternal IDURL
Hacker News50342931https://tibleiz.net/blog/2025-03-16-union-types-and-option-types.html Read discussion
Lobstersmwqrcthttps://tibleiz.net/blog/2025-03-16-union-types-and-option-types.html Read discussion