| Safe Haskell | None |
|---|---|
| Language | GHC2024 |
NumHask.Algebra.Additive
Description
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.
zero + a == a a + zero == a (a + b) + c == a + (b + c) 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 + 11
>>>1 + 12
>>>2 + zero == (2 :: Int)True
>>>(1 + 2) + 3 == 1 + (2 + 3)True
>>>2 + 3 == 3 + 2True
Instances
A wrapper for an Additive which distinguishes the additive structure
Since: 0.11.1
Instances
| Additive a => Monoid (Sum a) Source # | |
| Additive a => Semigroup (Sum a) Source # | |
| Eq a => Eq (Sum a) Source # | |
| Ord a => Ord (Sum a) Source # | |
| Show a => Show (Sum a) Source # | |
| Additive a => Additive (Sum a) Source # | |
| FromInteger a => FromInteger (Sum a) Source # | |
Defined in NumHask.Data.Integral Methods fromInteger :: Integer -> Sum a Source # | |
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 == zero negate a == zero - a negate a + a == zero a + negate a == zero
>>>negate 1-1
>>>1 - 2-1
>>>2 - 2 == (zero :: Int)True
>>>negate 2 == zero - (2 :: Int)True
>>>negate 2 + 2 == (zero :: Int)True
>>>2 + negate 2 == (zero :: Int)True