Portability | Haskell 98 |
---|---|

Stability | stable |

Maintainer | haskell@henning-thielemann.de |

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
- fromChunks :: C a => [a] -> T a
- fromNumber :: C a => a -> T a
- toChunks :: T a -> [a]
- toNumber :: C a => T a -> a
- zero :: T a
- normalize :: C a => T a -> T a
- isNull :: C a => T a -> Bool
- isPositive :: C a => T a -> Bool
- minMaxDiff :: C a => T a -> T a -> (T a, T a, Bool)
- divModStrict :: (Integral a, C a) => T a -> a -> (T a, a)
- fromChunksUnsafe :: [a] -> T a
- toChunksUnsafe :: T a -> [a]

# Documentation

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.

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

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

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

minMaxDiff :: C a => T a -> T a -> (T a, T a, Bool)Source

In `minMaxDiff x y == (z,r,b)`

`z`

represents `min x y`

,
`r`

represents `max x y - min x y`

,
and `xy == b`

or `x>y ==> not b`

,
for `x==y`

the value of b is arbitrary.

fromChunksUnsafe :: [a] -> T aSource

toChunksUnsafe :: T a -> [a]Source

This routine exposes the inner structure of the lazy number
and is actually the same as `toChunks`

.
It was considered dangerous,
but you can observe the lazy structure
in tying-the-knot applications anyway.
So the explicit revelation of the chunks seems not to be worse.