Safe Haskell | None |
---|---|

Language | Haskell2010 |

Non-negative numbers:

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

## Synopsis

- data NonNegative a
- getNonNegative :: NonNegative a -> a
- toNonNegative :: (Ord a, Num a) => a -> Maybe (NonNegative a)
- unsafeToNonNegative :: (Ord a, Num a) => a -> NonNegative a

# 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

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.