numhask-0.11.0.2: A numeric class hierarchy.
Safe HaskellSafe-Inferred
LanguageGHC2021

NumHask.Algebra.Additive

Description

Additive classes

Synopsis

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

Methods

(+) :: a -> a -> a infixl 6 Source #

zero :: a Source #

Instances

Instances details
Additive Int16 Source # 
Instance details

Defined in NumHask.Algebra.Additive

Additive Int32 Source # 
Instance details

Defined in NumHask.Algebra.Additive

Additive Int64 Source # 
Instance details

Defined in NumHask.Algebra.Additive

Additive Int8 Source # 
Instance details

Defined in NumHask.Algebra.Additive

Methods

(+) :: Int8 -> Int8 -> Int8 Source #

zero :: Int8 Source #

Additive Word16 Source # 
Instance details

Defined in NumHask.Algebra.Additive

Additive Word32 Source # 
Instance details

Defined in NumHask.Algebra.Additive

Additive Word64 Source # 
Instance details

Defined in NumHask.Algebra.Additive

Additive Word8 Source # 
Instance details

Defined in NumHask.Algebra.Additive

Additive Integer Source # 
Instance details

Defined in NumHask.Algebra.Additive

Additive Natural Source # 
Instance details

Defined in NumHask.Algebra.Additive

Additive Bool Source # 
Instance details

Defined in NumHask.Algebra.Additive

Methods

(+) :: Bool -> Bool -> Bool Source #

zero :: Bool Source #

Additive Double Source # 
Instance details

Defined in NumHask.Algebra.Additive

Additive Float Source # 
Instance details

Defined in NumHask.Algebra.Additive

Additive Int Source # 
Instance details

Defined in NumHask.Algebra.Additive

Methods

(+) :: Int -> Int -> Int Source #

zero :: Int Source #

Additive Word Source # 
Instance details

Defined in NumHask.Algebra.Additive

Methods

(+) :: Word -> Word -> Word Source #

zero :: Word Source #

Additive a => Additive (EuclideanPair a) Source # 
Instance details

Defined in NumHask.Algebra.Metric

Additive a => Additive (Complex a) Source # 
Instance details

Defined in NumHask.Data.Complex

Methods

(+) :: Complex a -> Complex a -> Complex a Source #

zero :: Complex a Source #

(Ord a, EndoBased a, Integral a, Ring a) => Additive (Ratio a) Source # 
Instance details

Defined in NumHask.Data.Rational

Methods

(+) :: Ratio a -> Ratio a -> Ratio a Source #

zero :: Ratio a Source #

Additive b => Additive (a -> b) Source # 
Instance details

Defined in NumHask.Algebra.Additive

Methods

(+) :: (a -> b) -> (a -> b) -> a -> b Source #

zero :: a -> b 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 - a == zero
\a -> negate a == zero - a
\a -> negate a + a == zero
\a -> a + negate a == zero
>>> negate 1
-1
>>> 1 - 2
-1

Minimal complete definition

(-) | negate

Methods

negate :: a -> a Source #

(-) :: a -> a -> a infixl 6 Source #

Instances

Instances details
Subtractive Int16 Source # 
Instance details

Defined in NumHask.Algebra.Additive

Subtractive Int32 Source # 
Instance details

Defined in NumHask.Algebra.Additive

Subtractive Int64 Source # 
Instance details

Defined in NumHask.Algebra.Additive

Subtractive Int8 Source # 
Instance details

Defined in NumHask.Algebra.Additive

Methods

negate :: Int8 -> Int8 Source #

(-) :: Int8 -> Int8 -> Int8 Source #

Subtractive Word16 Source # 
Instance details

Defined in NumHask.Algebra.Additive

Subtractive Word32 Source # 
Instance details

Defined in NumHask.Algebra.Additive

Subtractive Word64 Source # 
Instance details

Defined in NumHask.Algebra.Additive

Subtractive Word8 Source # 
Instance details

Defined in NumHask.Algebra.Additive

Subtractive Integer Source # 
Instance details

Defined in NumHask.Algebra.Additive

Subtractive Natural Source # 
Instance details

Defined in NumHask.Algebra.Additive

Subtractive Double Source # 
Instance details

Defined in NumHask.Algebra.Additive

Subtractive Float Source # 
Instance details

Defined in NumHask.Algebra.Additive

Subtractive Int Source # 
Instance details

Defined in NumHask.Algebra.Additive

Methods

negate :: Int -> Int Source #

(-) :: Int -> Int -> Int Source #

Subtractive Word Source # 
Instance details

Defined in NumHask.Algebra.Additive

Methods

negate :: Word -> Word Source #

(-) :: Word -> Word -> Word Source #

Subtractive a => Subtractive (EuclideanPair a) Source # 
Instance details

Defined in NumHask.Algebra.Metric

Subtractive a => Subtractive (Complex a) Source # 
Instance details

Defined in NumHask.Data.Complex

Methods

negate :: Complex a -> Complex a Source #

(-) :: Complex a -> Complex a -> Complex a Source #

(Ord a, EndoBased a, Integral a, Ring a) => Subtractive (Ratio a) Source # 
Instance details

Defined in NumHask.Data.Rational

Methods

negate :: Ratio a -> Ratio a Source #

(-) :: Ratio a -> Ratio a -> Ratio a Source #

Subtractive b => Subtractive (a -> b) Source # 
Instance details

Defined in NumHask.Algebra.Additive

Methods

negate :: (a -> b) -> a -> b Source #

(-) :: (a -> b) -> (a -> b) -> a -> b Source #