non-negative-0.0.3: Non-negative numbers

PortabilityHaskell 98



This module contains internal functions (*Unsafe) that I had liked to re-use in the NumericPrelude type hierarchy. However since the Eq and Ord instance already require the Num class, we cannot use that in the NumericPrelude.



data T a Source

A chunky non-negative number is a list of non-negative numbers. It represents the sum of the list elements. It is possible to represent a finite number with infinitely many chunks by using an infinite number of zeros.

Note the following problems:

Addition is commutative only for finite representations. E.g. let y = min (1+y) 2 in y is defined, let y = min (y+1) 2 in y is not.


C a => Eq (T a) 
C a => Num (T a) 
C a => Ord (T a) 
Show a => Show (T a) 
(C a, Arbitrary a) => Arbitrary (T a) 
C a => C (T a) 

fromChunks :: C a => [a] -> T aSource

fromNumber :: C a => a -> T aSource

toNumber :: C a => T a -> aSource

normalize :: C a => T a -> T aSource

Remove zero chunks.

isNull :: C a => T a -> BoolSource

isPositive :: C a => T a -> BoolSource

toChunksUnsafe :: T a -> [a]Source

This routine exposes the inner structure of the lazy number, and I think it should be used with care.