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

Edward Kmett ekmett at gmail.com
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
today.

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
converting

(&&) = (.&.)
(||) = (.|.)
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.

e.g.

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.

-Edward

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

> On Sun, Sep 28, 2014 at 2:54 PM, Edward Kmett <ekmett at gmail.com> 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 gmail.com
> ballbery at sinenomine.net
> unix, openafs, kerberos, infrastructure, xmonad
> http://sinenomine.net
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/libraries/attachments/20140928/8572966c/attachment.html>


More information about the Libraries mailing list