| Safe Haskell | None |
|---|---|
| Language | GHC2024 |
NumHask.Algebra.Multiplicative
Description
Multiplicative classes
Synopsis
- class Multiplicative a where
- newtype Product a = Product {
- getProduct :: a
- 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.
one * a == a a * one == a (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 * 22
>>>2 * 36
>>>2 * one == (2 :: Int)True
>>>(2 * 3) * 4 == 2 * (3 * 4)True
Instances
A wrapper for an Multiplicative which distinguishes the multiplicative structure
Since: 0.11.1
Constructors
| Product | |
Fields
| |
Instances
| Multiplicative a => Monoid (Product a) Source # | |
| Multiplicative a => Semigroup (Product a) Source # | |
| Eq a => Eq (Product a) Source # | |
| Ord a => Ord (Product a) Source # | |
| Show a => Show (Product a) Source # | |
| FromInteger a => FromInteger (Product a) Source # | |
Defined in NumHask.Data.Integral Methods fromInteger :: Integer -> Product a 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 / a ~= one || a == zero recip a ~= one / a || a == zero recip a * a ~= one || a == zero a * recip a ~= one || a == zero
>>>recip 2.00.5
>>>1 / 20.5
>>>let a = 4.0 in a / a ~= oneTrue
>>>let a = 4.0 in recip a ~= one / aTrue
>>>let a = 4.0 in recip a * a ~= oneTrue
>>>let a = 4.0 in a * recip a ~= oneTrue
Instances
| Divisive Double Source # | |
| Divisive Float Source # | |
| Divisive a => Divisive (TrivialAction a) Source # | |
Defined in NumHask.Algebra.Action Methods recip :: TrivialAction a -> TrivialAction a Source # (/) :: TrivialAction a -> TrivialAction a -> TrivialAction a Source # | |
| Divisive a => Divisive (EuclideanPair a) Source # | |
Defined in NumHask.Algebra.Metric Methods recip :: EuclideanPair a -> EuclideanPair a Source # (/) :: EuclideanPair a -> EuclideanPair a -> EuclideanPair a Source # | |
| (Subtractive a, Divisive a) => Divisive (Complex a) Source # | |
| Divisive a => Divisive (Positive a) Source # | |
| (Ord a, EndoBased a, Integral a, Ring a) => Divisive (Ratio a) Source # | |
| Divisive a => Divisive (Wrapped a) Source # | |
| Divisive b => Divisive (a -> b) Source # | |