Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Additive classes
Documentation
class Additive a where Source #
or Addition
For practical reasons, we begin the class tree with Additive
. Starting with Associative
and Unital
, or using Semigroup
and Monoid
from base tends to confuse the interface once you start having to disinguish between (say) monoidal addition and monoidal multiplication.
\a -> zero + a == a
\a -> a + zero == a
\a b c -> (a + b) + c == a + (b + c)
\a b -> a + b == b + a
By convention, (+) is regarded as commutative, but this is not universal, and the introduction of another symbol which means non-commutative addition seems a bit dogmatic.
>>>
zero + 1
1
>>>
1 + 1
2
Instances
Additive Int16 Source # | |
Additive Int32 Source # | |
Additive Int64 Source # | |
Additive Int8 Source # | |
Additive Word16 Source # | |
Additive Word32 Source # | |
Additive Word64 Source # | |
Additive Word8 Source # | |
Additive Integer Source # | |
Additive Natural Source # | |
Additive Bool Source # | |
Additive Double Source # | |
Additive Float Source # | |
Additive Int Source # | |
Additive Word Source # | |
Additive a => Additive (Sum a) Source # | |
Additive a => Additive (EuclideanPair a) Source # | |
Defined in NumHask.Algebra.Metric (+) :: EuclideanPair a -> EuclideanPair a -> EuclideanPair a Source # zero :: EuclideanPair a Source # | |
Additive a => Additive (Complex a) Source # | |
(Ord a, EndoBased a, Integral a, Ring a) => Additive (Ratio a) Source # | |
Additive b => Additive (a -> b) Source # | |
A wrapper for an Additive which distinguishes the additive structure
sum :: (Additive a, Foldable f) => f a -> a Source #
Compute the sum of a Foldable
.
>>>
sum [0..10]
55
accsum :: (Additive a, Traversable f) => f a -> f a Source #
Compute the accumulating sum of a Traversable
.
>>>
accsum [0..10]
[0,1,3,6,10,15,21,28,36,45,55]
class Additive a => Subtractive a where Source #
or Subtraction
\a -> a - a == zero
\a -> negate a == zero - a
\a -> negate a + a == zero
\a -> a + negate a == zero
>>>
negate 1
-1
>>>
1 - 2
-1
Instances
Subtractive Int16 Source # | |
Subtractive Int32 Source # | |
Subtractive Int64 Source # | |
Subtractive Int8 Source # | |
Subtractive Word16 Source # | |
Subtractive Word32 Source # | |
Subtractive Word64 Source # | |
Subtractive Word8 Source # | |
Subtractive Integer Source # | |
Subtractive Natural Source # | |
Subtractive Double Source # | |
Subtractive Float Source # | |
Subtractive Int Source # | |
Subtractive Word Source # | |
Subtractive a => Subtractive (EuclideanPair a) Source # | |
Defined in NumHask.Algebra.Metric negate :: EuclideanPair a -> EuclideanPair a Source # (-) :: EuclideanPair a -> EuclideanPair a -> EuclideanPair a Source # | |
Subtractive a => Subtractive (Complex a) Source # | |
(Ord a, EndoBased a, Integral a, Ring a) => Subtractive (Ratio a) Source # | |
Subtractive b => Subtractive (a -> b) Source # | |