num-non-negative-0.1: Non-negative numbers

Safe HaskellNone
LanguageHaskell2010

Numeric.NonNegative

Description

Non-negative numbers:

ghci> import Numeric.NonNegative
ghci> 2 + 3 :: NonNegative Double
5.0
ghci> 2 - 3 :: NonNegative Double
*** Exception: arithmetic underflow
Synopsis

Documentation

data NonNegative a Source #

An opaque newtype around a number n that asserts that n >= 0. The constructor is not exported to maintain the invariant.

Instances
(Inj p a, Ord a, Num a) => Inj p (NonNegative a) Source # 
Instance details

Defined in Numeric.NonNegative

Methods

inj :: p -> NonNegative a #

(Ord a, Num a, Enum a) => Enum (NonNegative a) Source #

Throws Underflow.

Instance details

Defined in Numeric.NonNegative

Eq a => Eq (NonNegative a) Source # 
Instance details

Defined in Numeric.NonNegative

(Ord a, Num a, Floating a) => Floating (NonNegative a) Source #

Throws Underflow.

Instance details

Defined in Numeric.NonNegative

(Ord a, Fractional a) => Fractional (NonNegative a) Source #

Throws Underflow.

Instance details

Defined in Numeric.NonNegative

Integral a => Integral (NonNegative a) Source # 
Instance details

Defined in Numeric.NonNegative

(Ord a, Num a) => Num (NonNegative a) Source #

Throws Underflow.

Instance details

Defined in Numeric.NonNegative

Ord a => Ord (NonNegative a) Source # 
Instance details

Defined in Numeric.NonNegative

(Ord a, Num a, Read a) => Read (NonNegative a) Source # 
Instance details

Defined in Numeric.NonNegative

Real a => Real (NonNegative a) Source # 
Instance details

Defined in Numeric.NonNegative

(Ord a, Num a, RealFloat a) => RealFloat (NonNegative a) Source #

Throws Underflow.

Instance details

Defined in Numeric.NonNegative

RealFrac a => RealFrac (NonNegative a) Source # 
Instance details

Defined in Numeric.NonNegative

Methods

properFraction :: Integral b => NonNegative a -> (b, NonNegative a) #

truncate :: Integral b => NonNegative a -> b #

round :: Integral b => NonNegative a -> b #

ceiling :: Integral b => NonNegative a -> b #

floor :: Integral b => NonNegative a -> b #

Show a => Show (NonNegative a) Source # 
Instance details

Defined in Numeric.NonNegative

Semigroup a => Semigroup (NonNegative a) Source # 
Instance details

Defined in Numeric.NonNegative

Monoid a => Monoid (NonNegative a) Source # 
Instance details

Defined in Numeric.NonNegative

PrintfArg a => PrintfArg (NonNegative a) Source # 
Instance details

Defined in Numeric.NonNegative

Storable a => Storable (NonNegative a) Source # 
Instance details

Defined in Numeric.NonNegative

getNonNegative :: NonNegative a -> a Source #

Unwrap the newtype.

toNonNegative :: (Ord a, Num a) => a -> Maybe (NonNegative a) Source #

Check if a number is non-negative and return Nothing if it is negative.

unsafeToNonNegative :: (Ord a, Num a) => a -> NonNegative a Source #

Check if a number is non-negative and throw Underflow if it is negative.