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

Herbert Valerio Riedel hvr at gnu.org
Tue Nov 11 14:25:28 UTC 2014


Hello Henning,

On 2014-11-11 at 14:11:25 +0100, Henning Thielemann wrote:
>> I hereby suggest to add a type for encoding term-level naturals
>>
>>  data Natural = <opaque/hidden>
>>       deriving (...the usual standard classes...)
>>
>> to `base:Data.Word` module
>
> This type is useful, no doubt. But so far Data.Word (and Data.Int) are
> modules for fixed size machine oriented integer types. 

Looking at the Haskell Report 2010 description of "Data.Word"[1]
there is no clear indication that an unbounded `Natural` would be out of
scope for "Data.Word" IMHO:

,----
| 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.
|
| ...
`----


> Would be nice to have Natural located where Integer is. Unfortunately,
> so far Integer is only exported by Prelude and GHC.Integer.

There's a couple of alternatives I can think of rightaway:

 1) Interpret "Data.Word" to really mean "unsigned integral types" as
    as the Haskell Report's heading seems to suggest

 2) Export 'Natural' from 'Prelude' (we recently exported 'Word' from
    the 'Prelude' as well, so...)

 3) Refrain from touching any Haskell Report controlled module, and just
    place the new type into a new GHC-specific module "GHC.Natural", if
    variant 1) and/or 2) fail to reach consensus at this time.

Cheers,
  hvr


 [1]: https://www.haskell.org/onlinereport/haskell2010/haskellch23.html#x31-26000023


More information about the Libraries mailing list