Reminds me of something I saw recently, a tri-value boolean, a "trilean" or "tribool". true, false, unknown
yes, no, maybe
nullable boolean
They all feel "risky" in terms of language design, like null itself. But I suppose there are languages with Maybe or Optional.> The tribool class acts like the built-in bool type, but for 3-state boolean logic https://www.boost.org/doc/libs/1_48_0/doc/html/tribool/tutor... Apparently this is also called "three-valued logic". > In logic, a three-valued logic (also trinary logic, trivalent, ternary, or trilean, sometimes abbreviated 3VL) is any of several many-valued logic systems in which there are three truth values indicating true, false, and some third value. > the primary motivation for research of three-valued logic is to represent the truth value of a statement that cannot be represented as true or false. https://en.wikipedia.org/wiki/Three-valued_logic Personally I think I'd prefer a language to instead support multiple return values, like result and optional error. Or a union of result and error types. > no reason not to use int8 directly Hm, so it gets into the territory of flags, bit fields, packed structs. const BitField = packed struct {
a: u3,
b: u3,
c: u2,
};
https://andrewkelley.me/post/a-better-way-to-implement-bit-f... |