Proposal: change the Bits instance for Bool to align with other basic types and support branchless calculations

Edward Kmett ekmett at
Sun Sep 28 19:14:47 UTC 2014

Like I mentioned earlier.

I don't think a fully fleshed out version of the alternative makes sense

Too many small changes would have to go in, and you'd need at least one
factoring of the Bits class to make it compelling.

But since you insist on trying to force me to provide a fully concrete
realization of a counter-proposal, here:

A fully consistent version of it would be to adopt short-circuiting across
all Bits instances (ugh), factor out testBit somehow, then consider

(&&) = (.&.)
(||) = (.|.)
and = getAll . foldMap All
or = Any . foldMap Any
any f = getAny . foldMap (Any . f)
all f = getAll . foldMap (All . f)
not = complement

for a suitably generalized Any and All.

If testBit didn't exist in the class, then you could support (&&) and (||)
for function spaces.


isAlnum = isDigit || isAlpha

with no new classes being constructed.

In a world where the current proposal does come to fruition, such a class
would be a separate ad hoc construction, and well, frankly that just would
probably never happen.

Like I said repeatedly above, I believe such a proposal doesn't have a
chance in hell of succeeding today, but the existence of possibilities in
that design space are why I'm hesitant to rush forward here.


On Sun, Sep 28, 2014 at 2:56 PM, Brandon Allbery <allbery.b at>

> On Sun, Sep 28, 2014 at 2:54 PM, Edward Kmett <ekmett at> wrote:
>> You've made it clear you have a very tight vision for the role of Bits. I
>> personally haven't yet committed to your viewpoint, but I can see the merit
>> of it. Like I said, I suspect that I've lost this debate.
> It might help if (a) we could see some examples of this alternative, and
> (b) how it interacts with the existing one. And I'm still left wondering
> how it relates to the non-Bool instances of Bits.
> --
> brandon s allbery kf8nh                               sine nomine
> associates
> allbery.b at
> ballbery at
> unix, openafs, kerberos, infrastructure, xmonad
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Libraries mailing list