nat-0.2: Lazy binary natural numbers




The implementations of all functions except for rem, quot, div, mod are supposed to be as non-strict as possible.



data Nat Source

Natural numbers and zero



Constructor representing zero

Pos Nat1

A natural number

Helper Functions

cmpNatLT :: Nat -> Nat -> OrderingSource

This function is used to implement lazy instances of compare and (<), (<=), (>), (>=). It is used to transfer information to more significant bits. Instead of yielding EQ it yields LT if the numbers are equal.

fromNat :: Num n => Nat -> nSource

This is used for the implementation of toInteger and fromEnum.

toNat :: (Integral n, Num n) => n -> NatSource

This is used for the implementation of fromInteger and toEnum.

Example Implementations using Nat

length :: [a] -> NatSource

take :: Nat -> [a] -> [a]Source

drop :: Nat -> [a] -> [a]Source

replicate :: Nat -> a -> [a]Source

Example Implementations using Num

lengthNum :: (Enum n, Num n) => [a] -> nSource

takeNum :: (Enum n, Num n) => n -> [a] -> [a]Source

dropNum :: (Enum n, Num n) => n -> [a] -> [a]Source

replicateNum :: (Enum n, Num n) => n -> a -> [a]Source