Confusion over bitSize, bitSizeMaybe, and finiteBitSize

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Confusion over bitSize, bitSizeMaybe, and finiteBitSize

chessai .
The documentation for these functions in Data.Bits say that these
functions do not evaluate their arguments. This wording is a bit
strange to me, since it seems that does not exactly mean that any such
implementation _must not_ evaluate its argument. This may be an issue
when dealing with types whose inhabitants have finite but not
necessarily fixed sizes. For example, there is a valid Bits instance
for strict ByteString, which is finite but not fixed-size.

My question is, should the wording be changed to be a bit clearer? Or
should this restriction exist in the first place?
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Confusion over bitSize, bitSizeMaybe, and finiteBitSize

Henning Thielemann

On Sun, 21 Jun 2020, chessai wrote:

> The documentation for these functions in Data.Bits say that these
> functions do not evaluate their arguments. This wording is a bit
> strange to me, since it seems that does not exactly mean that any such
> implementation _must not_ evaluate its argument. This may be an issue
> when dealing with types whose inhabitants have finite but not
> necessarily fixed sizes. For example, there is a valid Bits instance
> for strict ByteString, which is finite but not fixed-size.

Documentation of bitSizeMaybe says:

Returns Nothing for types that do not have a fixed bitsize, like Integer.

So, no evaluation of argument is necessary.

Of course, it would have been better to use a Proxy.
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries