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

wren romano winterkoninkje at
Tue Sep 30 22:59:14 UTC 2014

On Sun, Sep 28, 2014 at 2:45 PM, David Feuer <david.feuer at> wrote:
> I would think what you're trying to do would likely be better with a
> different class, by another name, supporting things like .&&., .||., etc.,
> or maybe even moving && and || into a class. Another direction is to look at
> structures representing other sorts of logics. I just don't see that
> Data.Bits is the right place to try to do these things.

I agree. The *current* use of (.&.) and (.|.) is for capturing strict
bitops and doing so as quickly as possible by trying to map them onto
CPU instructions. IMO it makes sense to codify this behavior as part
of the intention/goal of the Bits class. I'll gladly take the 10% if I
can get it, because that's what bit twiddling is all about.

The shortcircuiting behavior of (&&) and (||) is also nice to have on
hand, but it's currently restricted to Bool. If we want to generalize
this behavior to other types, then it makes sense to introduce a
separate class for generalizing these boolean operators. Doing so
would (a) allow greater consistency of the Bit instances, and (b)
allow other logical operators of a similar shortcircuitable nature
without assuming that the shortcircuiting logic ops are at all related
to the strict bitvector ops.

Live well,

More information about the Libraries mailing list