Safe Haskell | None |
---|---|
Language | Haskell98 |
- 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, +
, 0)
and the associative monoid is (R, *
, 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
:: a | |
-> a | |
-> a | Commutative Operation |
:: a | Commutative Unit |
:: a | |
-> a | |
-> a | Associative Operation |
:: a | Associative Unit |
:: Num a | |
=> a | Commutative Unit |
:: Num a | |
=> a | Associative Unit |
:: Num a | |
=> a | |
-> a | |
-> a | Commutative Operation |
:: Num a | |
=> a | |
-> a | |
-> a | Associative Operation |
(^) :: (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 #