Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add instance for Natural type #63

Closed
hvr opened this issue Dec 4, 2014 · 2 comments
Closed

Add instance for Natural type #63

hvr opened this issue Dec 4, 2014 · 2 comments

Comments

@hvr
Copy link
Member

hvr commented Dec 4, 2014

The Natural type has been officially added to base-4.8.0.0

@kolmodin
Copy link
Member

What differs between Integer and Natural, except that Natural cannot be negative?

data Natural = NatS#                 GmpLimb# -- ^ in @[0, maxBound::Word]@
             | NatJ# {-# UNPACK #-} !BigNat   -- ^ in @]maxBound::Word, +inf[@

We should probably not encode these internal constructors in the encoding format.
In general it looks similar to Integer, so we could use the same approach, or even piggyback on the Integer serialisation.

@hvr
Copy link
Member Author

hvr commented Dec 26, 2014

@kolmodin it's very similiar to Integer, except that it uses Word instead of Int for small values, and that obviously Natural can only represent non-negative numbers...

PS: Please take a look at

and (for GHC 7.8.*),

for primitives meant to be useful for serialising Integers and Naturals

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants