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

Safe HaskellSafe-Infered

Data.Nat

Description

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

Synopsis

Documentation

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)