| Safe Haskell | None |
|---|---|
| Language | Haskell98 |
Data.Semiring
Contents
- class Semiring a where
- (+) :: Semiring a => a -> a -> a
- (*) :: Semiring a => a -> a -> a
- (^) :: (Semiring a, Integral b) => a -> b -> 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
- class Semiring a => Ring a where
- (-) :: Ring a => a -> a -> a
- minus :: Ring a => a -> a -> a
Semiring typeclass
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: A commutative monoid and an
associative monoid. For any type R with a Num
instance, the commutative monoid is (R, '(Prelude.+)', 0)
and the associative monoid is (R, '(Prelude.*)', 1).
Instances should satisfy the following laws:
- additive identity
x+zero=zero+x = x
- additive associativity
x+(y+z) = (x+y)+z
- additive commutativity
x+y = y+x
- multiplicative identity
x*one=one*x = x
Methods
Arguments
| :: a | |
| -> a | |
| -> a | '(Prelude.+)' |
Arguments
| :: a | 0 |
Arguments
| :: a | |
| -> a | |
| -> a | '(Prelude.*)' |
Arguments
| :: a | 1 |
Arguments
| :: Num a | |
| => a | 0 |
Arguments
| :: Num a | |
| => a | 1 |
Arguments
| :: Num a | |
| => a | |
| -> a | |
| -> a | '(Prelude.+)' |
Arguments
| :: Num a | |
| => a | |
| -> a | |
| -> a | '(Prelude.*)' |
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.
Ring typeclass
class Semiring a => Ring a where Source #
Minimal complete definition
Instances