Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Multiplicative classes
Synopsis
- class Multiplicative a where
- product :: (Multiplicative a, Foldable f) => f a -> a
- accproduct :: (Multiplicative a, Traversable f) => f a -> f a
- class Multiplicative a => Divisive a where
Documentation
class Multiplicative a where Source #
For practical reasons, we begin the class tree with Additive
and Multiplicative
. 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 -> one * a == a
\a -> a * one == a
\a b c -> (a * b) * c == a * (b * c)
By convention, (*) is regarded as not necessarily commutative, but this is not universal, and the introduction of another symbol which means commutative multiplication seems a bit dogmatic.
>>>
one * 2
2
>>>
2 * 3
6
Instances
Multiplicative Int16 Source # | |
Multiplicative Int32 Source # | |
Multiplicative Int64 Source # | |
Multiplicative Int8 Source # | |
Multiplicative Word16 Source # | |
Multiplicative Word32 Source # | |
Multiplicative Word64 Source # | |
Multiplicative Word8 Source # | |
Multiplicative Integer Source # | |
Multiplicative Natural Source # | |
Multiplicative Bool Source # | |
Multiplicative Double Source # | |
Multiplicative Float Source # | |
Multiplicative Int Source # | |
Multiplicative Word Source # | |
Multiplicative a => Multiplicative (EuclideanPair a) Source # | |
Defined in NumHask.Algebra.Metric (*) :: EuclideanPair a -> EuclideanPair a -> EuclideanPair a Source # one :: EuclideanPair a Source # | |
(Subtractive a, Multiplicative a) => Multiplicative (Complex a) Source # | |
(Ord a, EndoBased a, Integral a, Ring a) => Multiplicative (Ratio a) Source # | |
Multiplicative b => Multiplicative (a -> b) Source # | |
product :: (Multiplicative a, Foldable f) => f a -> a Source #
Compute the product of a Foldable
.
>>>
product [1..5]
120
accproduct :: (Multiplicative a, Traversable f) => f a -> f a Source #
Compute the accumulating product of a Traversable
.
>>>
accproduct [1..5]
[1,2,6,24,120]
class Multiplicative a => Divisive a where Source #
or Division
Though unusual, the term Divisive usefully fits in with the grammer of other classes and avoids name clashes that occur with some popular libraries.
\(a :: Double) -> a / a ~= one || a == zero
\(a :: Double) -> recip a ~= one / a || a == zero
\(a :: Double) -> recip a * a ~= one || a == zero
\(a :: Double) -> a * recip a ~= one || a == zero
>>>
recip 2.0
0.5
>>>
1 / 2
0.5
Instances
Divisive Double Source # | |
Divisive Float Source # | |
(Subtractive a, Divisive a) => Divisive (EuclideanPair a) Source # | |
Defined in NumHask.Algebra.Metric recip :: EuclideanPair a -> EuclideanPair a Source # (/) :: EuclideanPair a -> EuclideanPair a -> EuclideanPair a Source # | |
(Subtractive a, Divisive a) => Divisive (Complex a) Source # | |
(Ord a, EndoBased a, Integral a, Ring a) => Divisive (Ratio a) Source # | |
Divisive b => Divisive (a -> b) Source # | |