Even More Tagged Union Subsets with Comptime
Mitchell Hashimoto demonstrates the use of tagged union subsets in Zig's comptime feature. This allows for the creation of more specific union types that can streamline function definitions for keyboard shortcuts in applications. The article also discusses a personal experience with implementing similar concepts in a parser for the MyST Markdown format.
- ▪Hashimoto shows how to derive specific unions for keyboard actions using Zig's comptime.
- ▪The specific union types help in writing functions that only accept relevant actions.
- ▪The author shares a personal project involving a parser for MyST, inspired by Hashimoto's approach.
Opening excerpt (first ~120 words) tap to expand
Even More Tagged Union Subsets with Comptime May 18, 2026 One of the cooler things you can do with Zig's comptime is create what Mitchell Hashimoto calls "tagged union subsets." Hashimoto shows how he can take an existing tagged union, one representing all possible keyboard shortcut actions in Ghostty, and use comptime to derive more specific unions representing just those actions affecting a particular terminal window or just those actions affecting the entire application. Having these more specific union types available means that he can write functions accepting only terminal-specific actions or only application-wide actions.
…
Excerpt limited to ~120 words for fair-use compliance. The full article is at Sinclairtarget.