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

Herbert Valerio Riedel hvr at
Tue Nov 11 09:35:20 UTC 2014

Hello CLC et al.,

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


 - GHC 7.10 is planned to ship with integer-gmp2[2] as its default
   `Integer` lib, whose low-level primitives are based on *unsigned*
   BigNums. And 'Natural' type for integer-gmp2 can be implemented
   directly w/o the overhead of wrapping an `Integer` via

     data Natural = NatS# Word# | NatJ# !PrimBigNat#

   as well as having a twice as large domain handled via the small-word
   constructor and thus avoiding FFI calls into GMP.

 - GHC/`base` already provides type-level naturals, but no term-level

 - Remove the asymmetry of having an unbounded signed `Integer` but no
   unbounded /unsigned/ integral type.

   Also, `Data.Word` has been carrying the following note[1] for some
   time now:
   > It would be very natural to add a type Natural providing an
   > unbounded size unsigned integer, just as Integer provides unbounded
   > size signed integers. We do not do that yet since there is no
   > demand for it.

Discussion period: ~10 days (GHC 7.10 RC freeze is scheduled for Nov 21st)




More information about the Libraries mailing list