3 ms·
> Can't make head or tail of what `zero_t` and `one_t` are about, or why they would be useful. I suspect it's the same problem C++ has/had (C++11 fixed it) wit
by SolarNet 9y ago
> Can't make head or tail of what `zero_t` and `one_t` are about, or why they would be useful.
I suspect it's the same problem C++ has/had (C++11 fixed it) with bools (see the safe bool idiom [0]). Basically treating a type like an integer (arithmetic object) and boolean (logical object) at the same time is problematic (especially for a "system" type meant for extending implicit system behavior). Because then I can do `if(BoolObject < 70)` when I only meant for `if(BoolObject)` to work (where "BoolObject" is some object evaluating to a bool, and by evaluating I mean coercing/casting).
Here it looks like they approached it by making 0/1 (effectively C's false/true) different types and relying on their simpler/more-powerful type system (e.g. because they don't have to worry about C++'s insane object system). Not a terrible idea if they were otherwise actually sticking to their goal of "evolving" C (most of their features are radical departures from the language like exceptions). C++11 solved it by clarifying how implicit explicit casting [sic] of rvalues works in certain keywords (which I strongly doubt anyone can say was the simpler way of solving the problem).
[0] https://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Safe_bool https://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Safe_bool