PROPOSAL: Add 'Natural' type to base:Data.Word

Herbert Valerio Riedel hvr at gnu.org
Tue Nov 11 15:01:08 UTC 2014


On 2014-11-11 at 15:30:49 +0100, Henning Thielemann wrote:
>> ,----
>> | 23.1 Unsigned integral types
>> |
>> | This module provides unsigned integer types of unspecified width (Word)
>> | and fixed widths (Word8, Word16, Word32 and Word64). All arithmetic is
>> | performed modulo 2^n, where n is the number of bits in the type.
>> |
>> | ...
>> `----
>
> "Number of bits in the type" suggests, that the number of bits depends
> only on the type, which is not true for Natural (and Integer), right?

Yeah, if that `n` is meant to mean a finite natural value, then you've
got a point here.

Otoh, one could maybe consider 'Natural' following modulo arithmetic 2^n
with an infinite number `n` of bits, and hence can never arithmetically
overflow. If an operation would, however, cause an underflow it simply
'throw (Underflows :: ArithException)'.

However, one could extend the Data.Word documentation to note
that 'Natural' represents an asymptotic limit/exception here with
respect to modulo 2^n arithmetic... :-)

Cheers,
  hvr


More information about the Libraries mailing list