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

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Artem Pelenitsyn
Dear Libraries,

I noticed the Numeric module has special-cased functions to read and show integral types in bases 8, 10, 16 but not for base 2. There are also generic-over-base versions, so an interested client can implement the special case for base 2 themselves with little hassle. Still, I think base 2 is common enough that we could support it along with base 8, 10, 16 out of the box.

What do you think? I'm happy to submit a merge request if you concur.

Kind regards,
Artem Pelenitsyn

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

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

David Feuer
Agreed!

On Sun, Dec 6, 2020, 1:03 PM Artem Pelenitsyn <[hidden email]> wrote:
Dear Libraries,

I noticed the Numeric module has special-cased functions to read and show integral types in bases 8, 10, 16 but not for base 2. There are also generic-over-base versions, so an interested client can implement the special case for base 2 themselves with little hassle. Still, I think base 2 is common enough that we could support it along with base 8, 10, 16 out of the box.

What do you think? I'm happy to submit a merge request if you concur.

Kind regards,
Artem Pelenitsyn
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

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

David Feuer
In reply to this post by Artem Pelenitsyn
In particular, I tend to want to print something out in base 2 when I'm fussing around with bit twiddling. The last thing I want to be thinking about at that point is writing a showing function.

On Sun, Dec 6, 2020, 1:03 PM Artem Pelenitsyn <[hidden email]> wrote:
Dear Libraries,

I noticed the Numeric module has special-cased functions to read and show integral types in bases 8, 10, 16 but not for base 2. There are also generic-over-base versions, so an interested client can implement the special case for base 2 themselves with little hassle. Still, I think base 2 is common enough that we could support it along with base 8, 10, 16 out of the box.

What do you think? I'm happy to submit a merge request if you concur.

Kind regards,
Artem Pelenitsyn
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

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

Oleg Grenrus
In reply to this post by David Feuer

+1

On 6.12.2020 20.04, David Feuer wrote:
Agreed!

On Sun, Dec 6, 2020, 1:03 PM Artem Pelenitsyn <[hidden email]> wrote:
Dear Libraries,

I noticed the Numeric module has special-cased functions to read and show integral types in bases 8, 10, 16 but not for base 2. There are also generic-over-base versions, so an interested client can implement the special case for base 2 themselves with little hassle. Still, I think base 2 is common enough that we could support it along with base 8, 10, 16 out of the box.

What do you think? I'm happy to submit a merge request if you concur.

Kind regards,
Artem Pelenitsyn
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

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

chessai .
+1

On Sun, Dec 6, 2020, 12:07 Oleg Grenrus <[hidden email]> wrote:

+1

On 6.12.2020 20.04, David Feuer wrote:
Agreed!

On Sun, Dec 6, 2020, 1:03 PM Artem Pelenitsyn <[hidden email]> wrote:
Dear Libraries,

I noticed the Numeric module has special-cased functions to read and show integral types in bases 8, 10, 16 but not for base 2. There are also generic-over-base versions, so an interested client can implement the special case for base 2 themselves with little hassle. Still, I think base 2 is common enough that we could support it along with base 8, 10, 16 out of the box.

What do you think? I'm happy to submit a merge request if you concur.

Kind regards,
Artem Pelenitsyn
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

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

Emily Pillmore
+1


On Sun, Dec 06, 2020 at 1:10 PM, chessai <[hidden email]> wrote:
+1

On Sun, Dec 6, 2020, 12:07 Oleg Grenrus <[hidden email]> wrote:

+1

On 6.12.2020 20.04, David Feuer wrote:
Agreed!

On Sun, Dec 6, 2020, 1:03 PM Artem Pelenitsyn <[hidden email]> wrote:
Dear Libraries,

I noticed the Numeric module has special-cased functions to read and show integral types in bases 8, 10, 16 but not for base 2. There are also generic-over-base versions, so an interested client can implement the special case for base 2 themselves with little hassle. Still, I think base 2 is common enough that we could support it along with base 8, 10, 16 out of the box.

What do you think? I'm happy to submit a merge request if you concur.

Kind regards,
Artem Pelenitsyn
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries



_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

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

Henning Thielemann

On Sun, 6 Dec 2020, Emily Pillmore wrote:

> +1
>
> On Sun, Dec 06, 2020 at 1:10 PM, chessai <[hidden email]> wrote:
>       +1
>
> On Sun, Dec 6, 2020, 12:07 Oleg Grenrus <[hidden email]> wrote:
>
>       +1


Base 2 +1 +1 +1 = Base 5 - Is this, what we want?
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

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

Tikhon Jelvis
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 <[hidden email]> wrote:

On Sun, 6 Dec 2020, Emily Pillmore wrote:

> +1
>
> On Sun, Dec 06, 2020 at 1:10 PM, chessai <[hidden email]> wrote:
>       +1
>
> On Sun, Dec 6, 2020, 12:07 Oleg Grenrus <[hidden email]> wrote:
>
>       +1


Base 2 +1 +1 +1 = Base 5 - Is this, what we want?
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

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

Andrew Martin
I need binary encode/decode about once every six months, and I too find it annoying that these are missing. +1 from me.

On Sun, Dec 6, 2020 at 3:09 PM Tikhon Jelvis <[hidden email]> wrote:
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 <[hidden email]> wrote:

On Sun, 6 Dec 2020, Emily Pillmore wrote:

> +1
>
> On Sun, Dec 06, 2020 at 1:10 PM, chessai <[hidden email]> wrote:
>       +1
>
> On Sun, Dec 6, 2020, 12:07 Oleg Grenrus <[hidden email]> wrote:
>
>       +1


Base 2 +1 +1 +1 = Base 5 - Is this, what we want?
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries


--
-Andrew Thaddeus Martin

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries