logoalt Hacker News

ruudalast Sunday at 9:35 PM4 repliesview on HN

> as name of the type, I think I like void more than ()

It's the wrong name though. In type theory, (), the type with one member, is traditionally called "Unit", while "Void" is the uninhabited type. Void is the return type of e.g. abort.


Replies

cornstalkslast Sunday at 10:16 PM

It fulfills the same role as C and C++'s void type. I don't think most systems programmers care about type theorist bikeshedding about purity with formal theory.

A ton of people coming to Zig are going to be coming from C and C++. void is fine.

ivanjermakovlast Sunday at 9:52 PM

If I understood `abort` semantics correctly, it has a type of `never` or Rust's `!`. Which has a meaning "unobtainable value because control flow went somwhere else". `void` is closer to `unit` or `()` because it's the type with no allowed values.

Cool trick: some languages (e.g. TypeScript) allow `void` generics making parameters of that type optional.

show 1 reply
netbsduserslast Monday at 7:12 PM

The void type has considerable heritage, dating back all the way to ALGOL 68, and is traditionally defined as having one member:

> The mode VOID has a single value denoted by EMPTY.

bmacholast Sunday at 10:14 PM

[deleted]

show 1 reply