WeSearch

Even More Tagged Union Subsets with Comptime

·14 min read · 0 reactions · 0 comments · 12 views
#programming#zig#markdown#comptime#software development
⚡ TL;DR · AI summary

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.

Key facts
Original article
Sinclairtarget
Read full at Sinclairtarget →
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.

Anonymous · no account needed
Share 𝕏 Facebook Reddit LinkedIn Threads WhatsApp Bluesky Mastodon Email

Discussion

0 comments

More from Sinclairtarget