Safe Haskell | None |
---|---|
Language | Haskell2010 |
Multiplicative classes
Synopsis
- class Multiplicative a where
- product :: (Multiplicative a, Foldable f) => f a -> 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
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