non-negative-0.1.1: Non-negative numbers

PortabilityHaskell 98
Stabilitystable
Maintainerhaskell@henning-thielemann.de
Safe HaskellSafe-Inferred

Numeric.NonNegative.Chunky

Description

A lazy number type, which is a generalization of lazy Peano numbers. Comparisons can be made lazy and thus computations are possible which are impossible with strict number types, e.g. you can compute let y = min (1+y) 2 in y. You can even work with infinite values. However, depending on the granularity, the memory consumption is higher than that for strict number types. This number type is of interest for the merge operation of event lists, which allows for co-recursive merges.

Synopsis

Documentation

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.

Instances

(Enum a, C a) => Enum (T a) 
C a => Eq (T a) 
(Integral a, C a) => Integral (T a) 
(C a, Num a) => Num (T a) 
C a => Ord (T a) 
(Real a, C a) => Real (T a) 
Show a => Show (T a) 
(C a, Arbitrary a) => Arbitrary (T a) 
Monoid (T a) 
C a => C (T a)

This instance is not correct with respect to the equality check if the involved numbers contain zero chunks.

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

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

toChunks :: T a -> [a]Source

This routine exposes the inner structure of the lazy number.

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

divModStrict :: (Integral a, C a) => T a -> a -> (T a, a)Source