logoalt Hacker News

continuationaltoday at 4:48 AM2 repliesview on HN

Sure, but this is an example from the article, and pertains to sum types in general, not just Maybe.


Replies

dnauticstoday at 5:13 AM

i dont think its generally a good idea to be making complex type generators like this in zig. just write the type out.

the annoyingness of the thing you tried to do in zig is a feature. its a "don't do this, you will confuse the reader" signal. as for optional, its a pattern that is so common that it's worth having builtin optimizations, for example @sizeOf(*T) == @sizeOf(usize) but @sizeOf(?*T) != @sizeOf(?usize). if optional were a general sum type you wouldn't be able to make these optimizations easily without extra information

show 2 replies