Copyright | Copyright (c) 2016 the Hakaru team |
---|---|
License | BSD3 |
Maintainer | wren@community.haskell.org |
Stability | experimental |
Portability | Haskell98 + CPP |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
A data type for natural numbers (aka non-negative integers).
Synopsis
- 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.
Instances
Enum Natural Source # | |
Eq Natural Source # | |
Integral Natural Source # | |
Defined in Data.Number.Natural | |
Num Natural Source # | |
Ord Natural Source # | |
Read Natural Source # | |
Real Natural Source # | |
Defined in Data.Number.Natural toRational :: Natural -> Rational # | |
Show Natural Source # | |
Interp 'HNat Natural Source # | |
Interp 'HProb NonNegativeRational Source # | |
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.
newtype MaxNatural Source #
Instances
Semigroup MaxNatural Source # | |
Defined in Data.Number.Natural (<>) :: MaxNatural -> MaxNatural -> MaxNatural # sconcat :: NonEmpty MaxNatural -> MaxNatural # stimes :: Integral b => b -> MaxNatural -> MaxNatural # | |
Monoid MaxNatural Source # | |
Defined in Data.Number.Natural mempty :: MaxNatural # mappend :: MaxNatural -> MaxNatural -> MaxNatural # mconcat :: [MaxNatural] -> MaxNatural # |
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.