Numeric supports base 8, 10, 16 but not 2 -- why?

Tikhon Jelvis tikhon at jelv.is
Sun Dec 6 20:09:02 UTC 2020


Absolutely agree on this. I've needed to render a number in binary a couple
of times, and each time I had to stop and think about how to use
showIntAtBase. It's not hard per se, but it is really fiddly. The
expression I end up using is hard to understand at a glance and uses a
scary-looking (but safe-ish) partial function:

    showIntAtBase 2 ("01" !!) x ""

A dedicated function is a clear improvement, although the ShowS bit is
still unnecessarily fiddly for use outside implementing Show instances:

  showBinary x ""

To be honest, I really don't like the Numeric module at all. I use hex a
bit more often than binary, but I just do it with printf. I was going to
suggest adding %b to printf alongside this change, but it looks like
Text.Printf already supports it! So while I think adding showBinary
absolutely makes sense, I'll probably just use printf myself going forwards.

On Sun, Dec 6, 2020 at 11:06 AM Henning Thielemann <
lemming at henning-thielemann.de> wrote:

>
> On Sun, 6 Dec 2020, Emily Pillmore wrote:
>
> > +1
> >
> > On Sun, Dec 06, 2020 at 1:10 PM, chessai <chessai1996 at gmail.com> wrote:
> >       +1
> >
> > On Sun, Dec 6, 2020, 12:07 Oleg Grenrus <oleg.grenrus at iki.fi> wrote:
> >
> >       +1
>
>
> Base 2 +1 +1 +1 = Base 5 - Is this, what we want?
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20201206/6db46b6f/attachment.html>


More information about the Libraries mailing list