| Safe Haskell | None |
|---|---|
| Language | Haskell98 |
Data.Semiring
- 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
Methods
Arguments
| :: a | |
| -> a | |
| -> a | Commutative Additive Operation |
Arguments
| :: a | Additive Unit |
Arguments
| :: a | |
| -> a | |
| -> a | Associative Multiplicative Operation |
Arguments
| :: a | Multiplicative Unit |
Arguments
| :: Num a | |
| => a | Additive Unit |
Arguments
| :: Num a | |
| => a | Multiplicative Unit |
Arguments
| :: Num a | |
| => a | |
| -> a | |
| -> a | Commutative Additive Operation |
Arguments
| :: Num a | |
| => a | |
| -> a | |
| -> a | Associative Multiplicative Operation |
Instances
class Semiring a => Ring a where Source #
Minimal complete definition
Instances
(^) :: (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.