Implement `Natural` number type (re #9818)
ClosedPublic

Authored by hvr on Nov 12 2014, 5:01 PM.

Details

Summary

This implements a Natural type for representing
unsigned arbitrary precision integers.

When available, integer-gmp>=1.0.0's BigNat is used as constituent
to construct Natural as an algebraic data-type.
Otherwise Natural falls back being a newtype-wrapper around Integer.

NOTE: Proposal discussion for adding Natural still in progress

Diff Detail

Repository
rGHC Glasgow Haskell Compiler
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
hvr updated this revision to Diff 1421.Nov 12 2014, 5:01 PM
hvr retitled this revision from to Implement `Natural` type.
hvr updated this object.
hvr edited the test plan for this revision. (Show Details)
hvr added a reviewer: ekmett.
hvr updated this object.Nov 13 2014, 2:52 AM
hvr edited edge metadata.
ekmett edited edge metadata.Nov 14 2014, 1:40 AM

Very clean!

hvr updated this revision to Diff 1588.Nov 20 2014, 5:12 AM
hvr edited edge metadata.
  • Add proposed re-exporting Data.Natural module
  • Improve Enum instance to handle [x,y..z] beyond the Int range.

Should we export it as Numeric.Natural? Numeric follows the classic top level module naming convention for numerics, and we've been lax and just throwing stuff in Data.

The existing nats package uses that corner of the namespace and has something like 150k downloads, so there are already a large number of users who using it from that place.

I'm happy to yield the module name, and slide the Whole machinery in nats to another module.

hvr added a comment.Nov 20 2014, 5:16 PM
In D473#13380, @ekmett wrote:

Should we export it as Numeric.Natural? Numeric follows the classic top level module naming convention for numerics, and we've been lax and just throwing stuff in Data.

Macro ihavenostrongfeelings:

I have no strong opinion here, so give me a CLC-blessed name for the module name to use... :-)

ekmett accepted this revision.Nov 20 2014, 6:24 PM
ekmett edited edge metadata.

All righty, take Numeric.Natural from me then.

This revision is now accepted and ready to land.Nov 20 2014, 6:24 PM
hvr retitled this revision from Implement `Natural` type to Implement `Natural` number type (re #9818).Nov 21 2014, 2:11 AM
hvr edited edge metadata.
hvr updated the Trac tickets for this revision.
hvr updated the Trac tickets for this revision.
hvr updated this revision to Diff 1627.Nov 21 2014, 9:10 AM
  • Rename Data.Natural to Numeric.Natural
  • Make Numerical.Natural trustworthy
  • Add fromIntegral rules
  • Expose a few GHC-specific Natural operations
  • Minor tweak to Enum instance
  • Define PrintfArg Natural instance

LGTM.

The only question I have is should the Data.OldList change be moved to another diff?

hvr added a comment.Nov 21 2014, 4:24 PM
In D473#13748, @ekmett wrote:

LGTM.

The only question I have is should the Data.OldList change be moved to another diff?

it's not part of this diff (that ones actually been already landed), it's just leaking through the rebased diff

austin accepted this revision.Nov 21 2014, 5:24 PM
austin edited edge metadata.

LGTM!

This revision was automatically updated to reflect the committed changes.