bool (was DConf 2019 AGM Livestream)
H. S. Teoh
hsteoh at quickfur.ath.cx
Mon May 13 13:00:55 UTC 2019
On Mon, May 13, 2019 at 07:16:04AM -0400, Andrei Alexandrescu via Digitalmars-d-announce wrote:
> On 5/12/19 11:46 PM, H. S. Teoh wrote:
> > On Sun, May 12, 2019 at 01:20:16PM +0000, Mike Franklin via Digitalmars-d-announce wrote:
> > [...]
> > > If anyone's looking for a challenge, I welcome them to propose a
> > > new `Bool` type (note the capital B) for inclusion in my new
> > > library.
> > [...]
> > As long as && and || continue to evaluate to a 1-bit integer, all
> > library efforts to implement Bool will be futile.
> When writing std.typecons.Ternary I thought of overloading opBinary
> for | and & to take a lazy argument on the right. I forgot why I ended
> up not doing it (I think it was because of code generation issues).
> This is something that could be made to work.
The problem is that && and || cannot be overloaded (and for very good
reasons -- it would open the door to C++-style egregious operator
overload abuse), and the alternatives & and | have the wrong precedence,
so you wouldn't be able to write boolean expressions with Bool naturally
the way you could with the built-in bool type. It would not be a drop-in
replacement and you would have to rewrite every single boolean
expression to use Bool instead, and that with a high chance of
introducing subtle errors because of the different precedence of & and
Boolean expressions and the associated boolean type is one of the things
that should be baked into the language (it'd be a mess otherwise), but
that also means that if the language doesn't get it right you have no
Too many people have open minds but closed eyes.
More information about the Digitalmars-d-announce