| Copyright | Copyright (c) 2016 the Hakaru team |
|---|---|
| License | BSD3 |
| Maintainer | wren@community.haskell.org |
| Stability | experimental |
| Portability | Haskell98 + CPP |
| Safe Haskell | Safe |
| Language | Haskell2010 |
Data.Number.Natural
Description
A data type for natural numbers (aka non-negative integers).
- data Natural
- fromNatural :: Natural -> Integer
- toNatural :: Integer -> Maybe Natural
- unsafeNatural :: Integer -> Natural
- newtype MaxNatural = MaxNatural {}
- type NonNegativeRational = Ratio Natural
- fromNonNegativeRational :: NonNegativeRational -> Rational
- toNonNegativeRational :: Rational -> Maybe NonNegativeRational
- unsafeNonNegativeRational :: Rational -> NonNegativeRational
Documentation
Natural numbers, with unbounded-width à la Integer. N.B.,
the Num instance will throw errors on subtraction, negation,
and fromInteger when the result is not a natural number.
fromNatural :: Natural -> Integer Source #
Safely convert a natural number to an integer.
toNatural :: Integer -> Maybe Natural Source #
Safely convert an integer to a natural number. Returns Nothing
if the integer is negative.
unsafeNatural :: Integer -> Natural Source #
Unsafely convert an integer to a natural number. Throws an error if the integer is negative.
type NonNegativeRational = Ratio Natural Source #
fromNonNegativeRational :: NonNegativeRational -> Rational Source #
Safely convert a non-negative rational to a rational.
toNonNegativeRational :: Rational -> Maybe NonNegativeRational Source #
Safely convert a rational to a non-negative rational. Returns
Nothing if the argument is negative.
unsafeNonNegativeRational :: Rational -> NonNegativeRational Source #
Unsafely convert a rational to a non-negative rational. Throws an error if the argument is negative.