numeric-prelude-0.1.2: An experimental alternative hierarchy of numeric type classesSource codeContentsIndex
Algebra.NonNegative
PortabilityHaskell 98
Stabilitystable
Maintainerhaskell@henning-thielemann.de
Description
A type class for non-negative numbers. Prominent instances are Numeric.NonNegative.Wrapper.T and peano numbers. This class cannot do any checks, but it let you show to the user what arguments your function expects. In fact many standard functions (take, '(!!)', ...) should have this type class constraint. Thus you must define class instances with care.
Synopsis
class (Ord a, C a) => C a where
(-|) :: a -> a -> a
Documentation
class (Ord a, C a) => C a whereSource
Instances of this class must ensure non-negative values. We cannot enforce this by types, but the type class constraint NonNegative.C avoids accidental usage of types which allow for negative numbers.
Methods
(-|) :: a -> a -> aSource
x -| y == max 0 (x-y)

The default implementation is not efficient, because it compares the values and then subtracts, again, if safe. max 0 (x-y) is more elegant and efficient but not possible in the general case, since x-y may already yield a negative number.

show/hide Instances
C T
(Ord a, C a) => C (T a)
C a => C (T a)
Produced by Haddock version 2.4.2