non-negative-0.1.2: Non-negative numbers

Copyright(c) Henning Thielemann 2008-2010
Maintainerhaskell@henning-thielemann.de
Stabilitystable
PortabilityHaskell 98
Safe HaskellSafe
LanguageHaskell98

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) Source # 

Methods

succ :: T a -> T a #

pred :: T a -> T a #

toEnum :: Int -> T a #

fromEnum :: T a -> Int #

enumFrom :: T a -> [T a] #

enumFromThen :: T a -> T a -> [T a] #

enumFromTo :: T a -> T a -> [T a] #

enumFromThenTo :: T a -> T a -> T a -> [T a] #

C a => Eq (T a) Source # 

Methods

(==) :: T a -> T a -> Bool #

(/=) :: T a -> T a -> Bool #

(Integral a, C a) => Integral (T a) Source # 

Methods

quot :: T a -> T a -> T a #

rem :: T a -> T a -> T a #

div :: T a -> T a -> T a #

mod :: T a -> T a -> T a #

quotRem :: T a -> T a -> (T a, T a) #

divMod :: T a -> T a -> (T a, T a) #

toInteger :: T a -> Integer #

(C a, Num a) => Num (T a) Source # 

Methods

(+) :: T a -> T a -> T a #

(-) :: T a -> T a -> T a #

(*) :: T a -> T a -> T a #

negate :: T a -> T a #

abs :: T a -> T a #

signum :: T a -> T a #

fromInteger :: Integer -> T a #

C a => Ord (T a) Source # 

Methods

compare :: T a -> T a -> Ordering #

(<) :: T a -> T a -> Bool #

(<=) :: T a -> T a -> Bool #

(>) :: T a -> T a -> Bool #

(>=) :: T a -> T a -> Bool #

max :: T a -> T a -> T a #

min :: T a -> T a -> T a #

(Real a, C a) => Real (T a) Source # 

Methods

toRational :: T a -> Rational #

Show a => Show (T a) Source # 

Methods

showsPrec :: Int -> T a -> ShowS #

show :: T a -> String #

showList :: [T a] -> ShowS #

Semigroup (T a) Source # 

Methods

(<>) :: T a -> T a -> T a #

sconcat :: NonEmpty (T a) -> T a #

stimes :: Integral b => b -> T a -> T a #

Monoid (T a) Source # 

Methods

mempty :: T a #

mappend :: T a -> T a -> T a #

mconcat :: [T a] -> T a #

(C a, Arbitrary a) => Arbitrary (T a) Source # 

Methods

arbitrary :: Gen (T a) #

shrink :: T a -> [T a] #

C a => C (T a) Source #

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

Methods

split :: T a -> T a -> (T a, (Bool, T a)) Source #

fromChunks :: C a => [a] -> T a Source #

fromNumber :: C a => a -> T a Source #

toChunks :: T a -> [a] Source #

This routine exposes the inner structure of the lazy number.

toNumber :: C a => T a -> a Source #

zero :: T a Source #

normalize :: C a => T a -> T a Source #

Remove zero chunks.

isNull :: C a => T a -> Bool Source #

isPositive :: C a => T a -> Bool Source #

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