data-nat-0.1.2: data Nat = Zero | Succ Nat

Safe HaskellSafe-Inferred

Data.Nat

Description

Operations which are undefined mathematically (0 / 0, infinity * 0, infinity - infinity, etc.) also have undefined results in this implementation.

Synopsis

Documentation

data Nat Source

Constructors

Zero 
Succ Nat 

Instances

Bounded Nat

maxBound = infinity. Not sure if this is polite.

Enum Nat 
Eq Nat 
Integral Nat 
Num Nat 
Ord Nat 
Read Nat 
Real Nat 
Show Nat 
Ix Nat 
Typeable Nat 
Generic Nat 
Whole Nat 

nat :: r -> (Nat -> r) -> Nat -> rSource

Shallow deconstruction. Returns the first argument if Zero, applies the second argument to the inner value if Succ.

foldNat :: r -> (r -> r) -> Nat -> rSource

Returns the first argument if Zero, applies the second argument recursively for each Succ.

unfoldNat :: (a -> Maybe a) -> a -> NatSource

Build a Nat from a seed value: the first argument should return the next seed value if the building is to continue, or Nothing if it is to stop. A Succ is added at each iteration.

infinity :: NatSource

Very big!

diff :: Nat -> Nat -> Either Nat NatSource

 diff n m | n >= m    = Right (n - m)
          | otherwise = Left  (m - n)