Safe Haskell | None |
---|---|
Language | Haskell98 |
- class Semiring a where
- class Semiring a => Ring a where
- (+) :: Semiring a => a -> a -> a
- (*) :: Semiring a => a -> a -> a
- (-) :: Ring a => a -> a -> a
- (^) :: (Semiring a, Integral b) => a -> b -> a
- minus :: Ring a => a -> a -> a
- foldMapP :: (Foldable t, Semiring s) => (a -> s) -> t a -> s
- foldMapT :: (Foldable t, Semiring s) => (a -> s) -> t a -> s
- sum :: (Foldable t, Semiring a) => t a -> a
- prod :: (Foldable t, Semiring a) => t a -> a
- sum' :: (Foldable t, Semiring a) => t a -> a
- prod' :: (Foldable t, Semiring a) => t a -> a
Documentation
class Semiring a where Source #
The class of semirings (types with two binary operations and two respective identities). One can think of a semiring as two monoids of the same underlying type: An commutative monoid and an associative one.
Instances should satisfy the following laws:
- additive identity
x+
zero
=zero
+
x = x
- additive associativity
x+
(y+
z) = (x+
y)+
z
- additive commutativity
- multiplicative identity
x*
one
=one
*
x = x
:: a | |
-> a | |
-> a | Commutative Additive Operation |
:: a | Additive Unit |
:: a | |
-> a | |
-> a | Associative Multiplicative Operation |
:: a | Multiplicative Unit |
:: Num a | |
=> a | Additive Unit |
:: Num a | |
=> a | Multiplicative Unit |
:: Num a | |
=> a | |
-> a | |
-> a | Commutative Additive Operation |
:: Num a | |
=> a | |
-> a | |
-> a | Associative Multiplicative Operation |
class Semiring a => Ring a where Source #
(^) :: (Semiring a, Integral b) => a -> b -> a infixr 8 Source #
Raise a number to a non-negative integral power.
If the power is negative, this will return zero
.
foldMapP :: (Foldable t, Semiring s) => (a -> s) -> t a -> s Source #
Map each element of the structure to a semiring, and combine the results
using plus
.
foldMapT :: (Foldable t, Semiring s) => (a -> s) -> t a -> s Source #
Map each element of the structure to a semiring, and combine the results
using times
.